[clang] 6966c06 - [clang] NFCI: Use `FileEntryRef` in `suggestPathToFileForDiagnostics()`
Jan Svoboda via cfe-commits
cfe-commits at lists.llvm.org
Sat Sep 9 20:49:43 PDT 2023
Author: Jan Svoboda
Date: 2023-09-09T20:29:04-07:00
New Revision: 6966c06bedd0639169ad82cf17ded235d0acb850
URL: https://github.com/llvm/llvm-project/commit/6966c06bedd0639169ad82cf17ded235d0acb850
DIFF: https://github.com/llvm/llvm-project/commit/6966c06bedd0639169ad82cf17ded235d0acb850.diff
LOG: [clang] NFCI: Use `FileEntryRef` in `suggestPathToFileForDiagnostics()`
Added:
Modified:
clang-tools-extra/clang-include-fixer/IncludeFixer.cpp
clang/include/clang/Lex/HeaderSearch.h
clang/include/clang/Lex/Preprocessor.h
clang/lib/Lex/HeaderSearch.cpp
clang/lib/Lex/PPDirectives.cpp
clang/lib/Sema/SemaLookup.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-include-fixer/IncludeFixer.cpp b/clang-tools-extra/clang-include-fixer/IncludeFixer.cpp
index 1bb5cf756b95b49..354f35cbadbeb94 100644
--- a/clang-tools-extra/clang-include-fixer/IncludeFixer.cpp
+++ b/clang-tools-extra/clang-include-fixer/IncludeFixer.cpp
@@ -307,7 +307,8 @@ std::string IncludeFixerSemaSource::minimizeInclude(
// Get the FileEntry for the include.
StringRef StrippedInclude = Include.trim("\"<>");
- auto Entry = SourceManager.getFileManager().getFile(StrippedInclude);
+ auto Entry =
+ SourceManager.getFileManager().getOptionalFileRef(StrippedInclude);
// If the file doesn't exist return the path from the database.
// FIXME: This should never happen.
diff --git a/clang/include/clang/Lex/HeaderSearch.h b/clang/include/clang/Lex/HeaderSearch.h
index 059b143535faaba..cec3a31c94800cd 100644
--- a/clang/include/clang/Lex/HeaderSearch.h
+++ b/clang/include/clang/Lex/HeaderSearch.h
@@ -870,7 +870,7 @@ class HeaderSearch {
///
/// \param IsAngled If non-null, filled in to indicate whether the suggested
/// path should be referenced as <Header.h> instead of "Header.h".
- std::string suggestPathToFileForDiagnostics(const FileEntry *File,
+ std::string suggestPathToFileForDiagnostics(FileEntryRef File,
llvm::StringRef MainFile,
bool *IsAngled = nullptr) const;
diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h
index 9efe439bc5f2192..bc1d94a61508d8d 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -2718,8 +2718,8 @@ class Preprocessor {
/// \return A file that can be #included to provide the desired effect. Null
/// if no such file could be determined or if a #include is not
/// appropriate (eg, if a module should be imported instead).
- const FileEntry *getHeaderToIncludeForDiagnostics(SourceLocation IncLoc,
- SourceLocation MLoc);
+ OptionalFileEntryRef getHeaderToIncludeForDiagnostics(SourceLocation IncLoc,
+ SourceLocation MLoc);
bool isRecordingPreamble() const {
return PreambleConditionalStack.isRecording();
diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index 699cd9ae03adc51..83ed2a991d2bd02 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -1923,11 +1923,8 @@ void HeaderSearch::loadSubdirectoryModuleMaps(DirectoryLookup &SearchDir) {
}
std::string HeaderSearch::suggestPathToFileForDiagnostics(
- const FileEntry *File, llvm::StringRef MainFile, bool *IsAngled) const {
- // FIXME: We assume that the path name currently cached in the FileEntry is
- // the most appropriate one for this analysis (and that it's spelled the
- // same way as the corresponding header search path).
- return suggestPathToFileForDiagnostics(File->getName(), /*WorkingDir=*/"",
+ FileEntryRef File, llvm::StringRef MainFile, bool *IsAngled) const {
+ return suggestPathToFileForDiagnostics(File.getName(), /*WorkingDir=*/"",
MainFile, IsAngled);
}
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index a4db8e7a84c07d5..7bb4dd3bc7eb690 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -874,7 +874,7 @@ Module *Preprocessor::getModuleForLocation(SourceLocation Loc,
: HeaderInfo.lookupModule(getLangOpts().CurrentModule, Loc);
}
-const FileEntry *
+OptionalFileEntryRef
Preprocessor::getHeaderToIncludeForDiagnostics(SourceLocation IncLoc,
SourceLocation Loc) {
Module *IncM = getModuleForLocation(
@@ -920,7 +920,7 @@ Preprocessor::getHeaderToIncludeForDiagnostics(SourceLocation IncLoc,
// make a particular module visible. Let the caller know they should
// suggest an import instead.
if (getLangOpts().ObjC || getLangOpts().CPlusPlusModules)
- return nullptr;
+ return std::nullopt;
// If this is an accessible, non-textual header of M's top-level module
// that transitively includes the given location and makes the
@@ -931,7 +931,7 @@ Preprocessor::getHeaderToIncludeForDiagnostics(SourceLocation IncLoc,
// FIXME: If we're bailing out due to a private header, we shouldn't suggest
// an import either.
if (InPrivateHeader)
- return nullptr;
+ return std::nullopt;
// If the header is includable and has an include guard, assume the
// intended way to expose its contents is by #include, not by importing a
@@ -942,7 +942,7 @@ Preprocessor::getHeaderToIncludeForDiagnostics(SourceLocation IncLoc,
Loc = SM.getIncludeLoc(ID);
}
- return nullptr;
+ return std::nullopt;
}
OptionalFileEntryRef Preprocessor::LookupFile(
diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 7dd96e3155e1dd4..324a57095560b79 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -5699,7 +5699,7 @@ void Sema::diagnoseMissingImport(SourceLocation Loc, const NamedDecl *Decl,
/// Get a "quoted.h" or <angled.h> include path to use in a diagnostic
/// suggesting the addition of a #include of the specified file.
-static std::string getHeaderNameForHeader(Preprocessor &PP, const FileEntry *E,
+static std::string getHeaderNameForHeader(Preprocessor &PP, FileEntryRef E,
llvm::StringRef IncludingFile) {
bool IsAngled = false;
auto Path = PP.getHeaderSearchInfo().suggestPathToFileForDiagnostics(
@@ -5732,11 +5732,12 @@ void Sema::diagnoseMissingImport(SourceLocation UseLoc, const NamedDecl *Decl,
// Try to find a suitable header-name to #include.
std::string HeaderName;
- if (const FileEntry *Header =
+ if (OptionalFileEntryRef Header =
PP.getHeaderToIncludeForDiagnostics(UseLoc, DeclLoc)) {
if (const FileEntry *FE =
SourceMgr.getFileEntryForID(SourceMgr.getFileID(UseLoc)))
- HeaderName = getHeaderNameForHeader(PP, Header, FE->tryGetRealPathName());
+ HeaderName =
+ getHeaderNameForHeader(PP, *Header, FE->tryGetRealPathName());
}
// If we have a #include we should suggest, or if all definition locations
More information about the cfe-commits
mailing list