Skip to content

Commit 6966c06

Browse files
committed
[clang] NFCI: Use FileEntryRef in suggestPathToFileForDiagnostics()
1 parent 86f21e9 commit 6966c06

File tree

6 files changed

+15
-16
lines changed

6 files changed

+15
-16
lines changed

clang-tools-extra/clang-include-fixer/IncludeFixer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ std::string IncludeFixerSemaSource::minimizeInclude(
307307

308308
// Get the FileEntry for the include.
309309
StringRef StrippedInclude = Include.trim("\"<>");
310-
auto Entry = SourceManager.getFileManager().getFile(StrippedInclude);
310+
auto Entry =
311+
SourceManager.getFileManager().getOptionalFileRef(StrippedInclude);
311312

312313
// If the file doesn't exist return the path from the database.
313314
// FIXME: This should never happen.

clang/include/clang/Lex/HeaderSearch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ class HeaderSearch {
870870
///
871871
/// \param IsAngled If non-null, filled in to indicate whether the suggested
872872
/// path should be referenced as <Header.h> instead of "Header.h".
873-
std::string suggestPathToFileForDiagnostics(const FileEntry *File,
873+
std::string suggestPathToFileForDiagnostics(FileEntryRef File,
874874
llvm::StringRef MainFile,
875875
bool *IsAngled = nullptr) const;
876876

clang/include/clang/Lex/Preprocessor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2718,8 +2718,8 @@ class Preprocessor {
27182718
/// \return A file that can be #included to provide the desired effect. Null
27192719
/// if no such file could be determined or if a #include is not
27202720
/// appropriate (eg, if a module should be imported instead).
2721-
const FileEntry *getHeaderToIncludeForDiagnostics(SourceLocation IncLoc,
2722-
SourceLocation MLoc);
2721+
OptionalFileEntryRef getHeaderToIncludeForDiagnostics(SourceLocation IncLoc,
2722+
SourceLocation MLoc);
27232723

27242724
bool isRecordingPreamble() const {
27252725
return PreambleConditionalStack.isRecording();

clang/lib/Lex/HeaderSearch.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,11 +1923,8 @@ void HeaderSearch::loadSubdirectoryModuleMaps(DirectoryLookup &SearchDir) {
19231923
}
19241924

19251925
std::string HeaderSearch::suggestPathToFileForDiagnostics(
1926-
const FileEntry *File, llvm::StringRef MainFile, bool *IsAngled) const {
1927-
// FIXME: We assume that the path name currently cached in the FileEntry is
1928-
// the most appropriate one for this analysis (and that it's spelled the
1929-
// same way as the corresponding header search path).
1930-
return suggestPathToFileForDiagnostics(File->getName(), /*WorkingDir=*/"",
1926+
FileEntryRef File, llvm::StringRef MainFile, bool *IsAngled) const {
1927+
return suggestPathToFileForDiagnostics(File.getName(), /*WorkingDir=*/"",
19311928
MainFile, IsAngled);
19321929
}
19331930

clang/lib/Lex/PPDirectives.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ Module *Preprocessor::getModuleForLocation(SourceLocation Loc,
874874
: HeaderInfo.lookupModule(getLangOpts().CurrentModule, Loc);
875875
}
876876

877-
const FileEntry *
877+
OptionalFileEntryRef
878878
Preprocessor::getHeaderToIncludeForDiagnostics(SourceLocation IncLoc,
879879
SourceLocation Loc) {
880880
Module *IncM = getModuleForLocation(
@@ -920,7 +920,7 @@ Preprocessor::getHeaderToIncludeForDiagnostics(SourceLocation IncLoc,
920920
// make a particular module visible. Let the caller know they should
921921
// suggest an import instead.
922922
if (getLangOpts().ObjC || getLangOpts().CPlusPlusModules)
923-
return nullptr;
923+
return std::nullopt;
924924

925925
// If this is an accessible, non-textual header of M's top-level module
926926
// that transitively includes the given location and makes the
@@ -931,7 +931,7 @@ Preprocessor::getHeaderToIncludeForDiagnostics(SourceLocation IncLoc,
931931
// FIXME: If we're bailing out due to a private header, we shouldn't suggest
932932
// an import either.
933933
if (InPrivateHeader)
934-
return nullptr;
934+
return std::nullopt;
935935

936936
// If the header is includable and has an include guard, assume the
937937
// intended way to expose its contents is by #include, not by importing a
@@ -942,7 +942,7 @@ Preprocessor::getHeaderToIncludeForDiagnostics(SourceLocation IncLoc,
942942
Loc = SM.getIncludeLoc(ID);
943943
}
944944

945-
return nullptr;
945+
return std::nullopt;
946946
}
947947

948948
OptionalFileEntryRef Preprocessor::LookupFile(

clang/lib/Sema/SemaLookup.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5699,7 +5699,7 @@ void Sema::diagnoseMissingImport(SourceLocation Loc, const NamedDecl *Decl,
56995699

57005700
/// Get a "quoted.h" or <angled.h> include path to use in a diagnostic
57015701
/// suggesting the addition of a #include of the specified file.
5702-
static std::string getHeaderNameForHeader(Preprocessor &PP, const FileEntry *E,
5702+
static std::string getHeaderNameForHeader(Preprocessor &PP, FileEntryRef E,
57035703
llvm::StringRef IncludingFile) {
57045704
bool IsAngled = false;
57055705
auto Path = PP.getHeaderSearchInfo().suggestPathToFileForDiagnostics(
@@ -5732,11 +5732,12 @@ void Sema::diagnoseMissingImport(SourceLocation UseLoc, const NamedDecl *Decl,
57325732

57335733
// Try to find a suitable header-name to #include.
57345734
std::string HeaderName;
5735-
if (const FileEntry *Header =
5735+
if (OptionalFileEntryRef Header =
57365736
PP.getHeaderToIncludeForDiagnostics(UseLoc, DeclLoc)) {
57375737
if (const FileEntry *FE =
57385738
SourceMgr.getFileEntryForID(SourceMgr.getFileID(UseLoc)))
5739-
HeaderName = getHeaderNameForHeader(PP, Header, FE->tryGetRealPathName());
5739+
HeaderName =
5740+
getHeaderNameForHeader(PP, *Header, FE->tryGetRealPathName());
57405741
}
57415742

57425743
// If we have a #include we should suggest, or if all definition locations

0 commit comments

Comments
 (0)