[clang] 3473f72 - [clang][lex] NFCI: Use DirectoryEntryRef in HeaderSearch::LookupFile
Jan Svoboda via cfe-commits
cfe-commits at lists.llvm.org
Tue May 30 21:42:07 PDT 2023
Author: Jan Svoboda
Date: 2023-05-30T21:42:01-07:00
New Revision: 3473f728b36e21d322f141e576377c20a02c9aad
URL: https://github.com/llvm/llvm-project/commit/3473f728b36e21d322f141e576377c20a02c9aad
DIFF: https://github.com/llvm/llvm-project/commit/3473f728b36e21d322f141e576377c20a02c9aad.diff
LOG: [clang][lex] NFCI: Use DirectoryEntryRef in HeaderSearch::LookupFile
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
Added:
Modified:
clang/include/clang/Lex/HeaderSearch.h
clang/lib/Frontend/FrontendAction.cpp
clang/lib/Lex/HeaderSearch.cpp
clang/lib/Lex/PPDirectives.cpp
clang/test/Modules/filename.cpp
Removed:
clang/test/Modules/Inputs/filename/a.h
clang/test/Modules/Inputs/filename/module.map
################################################################################
diff --git a/clang/include/clang/Lex/HeaderSearch.h b/clang/include/clang/Lex/HeaderSearch.h
index 2a4e046be46fd..d3ee4963fced9 100644
--- a/clang/include/clang/Lex/HeaderSearch.h
+++ b/clang/include/clang/Lex/HeaderSearch.h
@@ -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,
diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp
index c5893874e1d32..cfac2f8c4e5a6 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -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() ==
diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index 7df1ca16f67ce..3366f158fd4f7 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -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,
@@ -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());
@@ -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());
}
@@ -967,7 +967,7 @@ OptionalFileEntryRef HeaderSearch::LookupFile(
}
if (First) {
diagnoseFrameworkInclude(Diags, IncludeLoc,
- IncluderAndDir.second->getName(), Filename,
+ IncluderAndDir.second.getName(), Filename,
&FE->getFileEntry());
return FE;
}
@@ -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.
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 1a5398e3adea6..b3ce92f1699da 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -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
@@ -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
@@ -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()));
}
}
}
diff --git a/clang/test/Modules/Inputs/filename/a.h b/clang/test/Modules/Inputs/filename/a.h
deleted file mode 100644
index 8f896a9ba8f41..0000000000000
--- a/clang/test/Modules/Inputs/filename/a.h
+++ /dev/null
@@ -1 +0,0 @@
-const char *p = __FILE__;
diff --git a/clang/test/Modules/Inputs/filename/module.map b/clang/test/Modules/Inputs/filename/module.map
deleted file mode 100644
index ff164ad7bac8e..0000000000000
--- a/clang/test/Modules/Inputs/filename/module.map
+++ /dev/null
@@ -1,3 +0,0 @@
-module "A" {
- header "a.h"
-}
diff --git a/clang/test/Modules/filename.cpp b/clang/test/Modules/filename.cpp
index e2b5ad141891f..7c42a7eddee38 100644
--- a/clang/test/Modules/filename.cpp
+++ b/clang/test/Modules/filename.cpp
@@ -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"
More information about the cfe-commits
mailing list