Skip to content

Commit

Permalink
[clang][lex] NFCI: Use DirectoryEntryRef in HeaderSearch::LookupFile
Browse files Browse the repository at this point in the history
This patch changes the argument type to `HeaderSearch::LookupFile()` from `const DirectoryEntry *` to `DirectoryEntryRef` in order to remove some calls to the deprecated `DirectoryEntry::getName()`.

Depends on D127660.

Reviewed By: bnbarham, benlangmuir

Differential Revision: https://reviews.llvm.org/D127663
  • Loading branch information
jansvoboda11 committed May 31, 2023
1 parent 9bd3ff8 commit 3473f72
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 28 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/Lex/HeaderSearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ class HeaderSearch {
OptionalFileEntryRef LookupFile(
StringRef Filename, SourceLocation IncludeLoc, bool isAngled,
ConstSearchDirIterator FromDir, ConstSearchDirIterator *CurDir,
ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>> Includers,
ArrayRef<std::pair<const FileEntry *, DirectoryEntryRef>> Includers,
SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath,
Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule,
bool *IsMapped, bool *IsFrameworkFound, bool SkipCache = false,
Expand Down
8 changes: 3 additions & 5 deletions clang/lib/Frontend/FrontendAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -825,11 +825,9 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
"trying to build a header unit without a Pre-processor?");
HeaderSearch &HS = CI.getPreprocessor().getHeaderSearchInfo();
// Relative searches begin from CWD.
const DirectoryEntry *Dir = nullptr;
if (auto DirOrErr = CI.getFileManager().getDirectory("."))
Dir = *DirOrErr;
SmallVector<std::pair<const FileEntry *, const DirectoryEntry *>, 1> CWD;
CWD.push_back({nullptr, Dir});
auto Dir = CI.getFileManager().getOptionalDirectoryRef(".");
SmallVector<std::pair<const FileEntry *, DirectoryEntryRef>, 1> CWD;
CWD.push_back({nullptr, *Dir});
OptionalFileEntryRef FE =
HS.LookupFile(FileName, SourceLocation(),
/*Angled*/ Input.getKind().getHeaderUnitKind() ==
Expand Down
10 changes: 5 additions & 5 deletions clang/lib/Lex/HeaderSearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ diagnoseFrameworkInclude(DiagnosticsEngine &Diags, SourceLocation IncludeLoc,
OptionalFileEntryRef HeaderSearch::LookupFile(
StringRef Filename, SourceLocation IncludeLoc, bool isAngled,
ConstSearchDirIterator FromDir, ConstSearchDirIterator *CurDirArg,
ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>> Includers,
ArrayRef<std::pair<const FileEntry *, DirectoryEntryRef>> Includers,
SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath,
Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule,
bool *IsMapped, bool *IsFrameworkFound, bool SkipCache,
Expand Down Expand Up @@ -918,7 +918,7 @@ OptionalFileEntryRef HeaderSearch::LookupFile(

// Concatenate the requested file onto the directory.
// FIXME: Portability. Filename concatenation should be in sys::Path.
TmpDir = IncluderAndDir.second->getName();
TmpDir = IncluderAndDir.second.getName();
TmpDir.push_back('/');
TmpDir.append(Filename.begin(), Filename.end());

Expand Down Expand Up @@ -957,7 +957,7 @@ OptionalFileEntryRef HeaderSearch::LookupFile(
ToHFI.Framework = Framework;

if (SearchPath) {
StringRef SearchPathRef(IncluderAndDir.second->getName());
StringRef SearchPathRef(IncluderAndDir.second.getName());
SearchPath->clear();
SearchPath->append(SearchPathRef.begin(), SearchPathRef.end());
}
Expand All @@ -967,7 +967,7 @@ OptionalFileEntryRef HeaderSearch::LookupFile(
}
if (First) {
diagnoseFrameworkInclude(Diags, IncludeLoc,
IncluderAndDir.second->getName(), Filename,
IncluderAndDir.second.getName(), Filename,
&FE->getFileEntry());
return FE;
}
Expand Down Expand Up @@ -1122,7 +1122,7 @@ OptionalFileEntryRef HeaderSearch::LookupFile(
bool FoundByHeaderMap = !IsMapped ? false : *IsMapped;
if (!Includers.empty())
diagnoseFrameworkInclude(
Diags, IncludeLoc, Includers.front().second->getName(), Filename,
Diags, IncludeLoc, Includers.front().second.getName(), Filename,
&File->getFileEntry(), isAngled, FoundByHeaderMap);

// Remember this location for the next lookup we do.
Expand Down
17 changes: 9 additions & 8 deletions clang/lib/Lex/PPDirectives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -935,12 +935,11 @@ OptionalFileEntryRef Preprocessor::LookupFile(

// If the header lookup mechanism may be relative to the current inclusion
// stack, record the parent #includes.
SmallVector<std::pair<const FileEntry *, const DirectoryEntry *>, 16>
Includers;
SmallVector<std::pair<const FileEntry *, DirectoryEntryRef>, 16> Includers;
bool BuildSystemModule = false;
if (!FromDir && !FromFile) {
FileID FID = getCurrentFileLexer()->getFileID();
const FileEntry *FileEnt = SourceMgr.getFileEntryForID(FID);
OptionalFileEntryRef FileEnt = SourceMgr.getFileEntryRefForID(FID);

// If there is no file entry associated with this file, it must be the
// predefines buffer or the module includes buffer. Any other file is not
Expand All @@ -958,11 +957,13 @@ OptionalFileEntryRef Preprocessor::LookupFile(
if (FID == SourceMgr.getMainFileID() && MainFileDir) {
Includers.push_back(std::make_pair(nullptr, *MainFileDir));
BuildSystemModule = getCurrentModule()->IsSystem;
} else if ((FileEnt =
SourceMgr.getFileEntryForID(SourceMgr.getMainFileID())))
Includers.push_back(std::make_pair(FileEnt, *FileMgr.getDirectory(".")));
} else if ((FileEnt = SourceMgr.getFileEntryRefForID(
SourceMgr.getMainFileID()))) {
auto CWD = FileMgr.getOptionalDirectoryRef(".");
Includers.push_back(std::make_pair(*FileEnt, *CWD));
}
} else {
Includers.push_back(std::make_pair(FileEnt, FileEnt->getDir()));
Includers.push_back(std::make_pair(*FileEnt, FileEnt->getDir()));
}

// MSVC searches the current include stack from top to bottom for
Expand All @@ -972,7 +973,7 @@ OptionalFileEntryRef Preprocessor::LookupFile(
for (IncludeStackInfo &ISEntry : llvm::reverse(IncludeMacroStack)) {
if (IsFileLexer(ISEntry))
if ((FileEnt = ISEntry.ThePPLexer->getFileEntry()))
Includers.push_back(std::make_pair(FileEnt, FileEnt->getDir()));
Includers.push_back(std::make_pair(*FileEnt, FileEnt->getDir()));
}
}
}
Expand Down
1 change: 0 additions & 1 deletion clang/test/Modules/Inputs/filename/a.h

This file was deleted.

3 changes: 0 additions & 3 deletions clang/test/Modules/Inputs/filename/module.map

This file was deleted.

19 changes: 14 additions & 5 deletions clang/test/Modules/filename.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
// RUN: cd %S
// RUN: %clang_cc1 -I. -fmodule-name=A -fmodule-map-file=%S/Inputs/filename/module.map %s -E | FileCheck %s
// RUN: rm -rf %t
// RUN: split-file %s %t

#include "Inputs/filename/a.h"
//--- include/a.h
const char *p = __FILE__;
//--- include/module.modulemap
module "A" { header "a.h" }
//--- src/tu.cpp
#include "a.h"

// RUN: cd %t
// RUN: %clang_cc1 -I ./include -fmodule-name=A -fmodule-map-file=%t/include/module.modulemap %t/src/tu.cpp -E | FileCheck %s

// Make sure that headers that are referenced by module maps have __FILE__
// reflect the include path they were found with.
// CHECK: const char *p = "./Inputs/filename/a.h"
// reflect the include path they were found with. (We make sure they cannot be
// found relative to the includer.)
// CHECK: const char *p = "./include{{/|\\\\}}a.h"

0 comments on commit 3473f72

Please sign in to comment.