Author: Jan Svoboda Date: 2023-09-08T19:04:01-07:00 New Revision: 523c471250a49b5603bd907ff05535f18ef61c91
URL: https://github.com/llvm/llvm-project/commit/523c471250a49b5603bd907ff05535f18ef61c91 DIFF: https://github.com/llvm/llvm-project/commit/523c471250a49b5603bd907ff05535f18ef61c91.diff LOG: Reapply "[clang] NFCI: Adopt `SourceManager::getFileEntryRefForID()`" This reapplies ddbcc10b9e26b18f6a70e23d0611b9da75ffa52f, except for a tiny part that was reverted separately: 65331da0032ab4253a4bc0ddcb2da67664bd86a9. That will be reapplied later on, since it turned out to be more involved. This commit is enabled by 5523fefb01c282c4cbcaf6314a9aaf658c6c145f and f0f548a65a215c450d956dbcedb03656449705b9, specifically the part that makes 'clang-tidy/checkers/misc/header-include-cycle.cpp' separator agnostic. Added: Modified: clang/include/clang/ASTMatchers/ASTMatchers.h clang/include/clang/Basic/SourceLocation.h clang/lib/ARCMigrate/ARCMT.cpp clang/lib/ARCMigrate/ObjCMT.cpp clang/lib/ARCMigrate/PlistReporter.cpp clang/lib/AST/MicrosoftMangle.cpp clang/lib/Analysis/PathDiagnostic.cpp clang/lib/Basic/SourceLocation.cpp clang/lib/Basic/SourceManager.cpp clang/lib/CodeGen/CodeGenModule.cpp clang/lib/Frontend/ASTUnit.cpp clang/lib/Frontend/FrontendAction.cpp clang/lib/Frontend/HeaderIncludeGen.cpp clang/lib/Frontend/LogDiagnosticPrinter.cpp clang/lib/Frontend/PrecompiledPreamble.cpp clang/lib/Frontend/Rewrite/FixItRewriter.cpp clang/lib/Frontend/Rewrite/HTMLPrint.cpp clang/lib/Frontend/SARIFDiagnostic.cpp clang/lib/Frontend/TextDiagnostic.cpp clang/lib/Frontend/VerifyDiagnosticConsumer.cpp clang/lib/Index/CommentToXML.cpp clang/lib/Index/USRGeneration.cpp clang/lib/Sema/Sema.cpp clang/lib/Sema/SemaModule.cpp clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp clang/lib/Tooling/Core/Replacement.cpp clang/lib/Tooling/Refactoring/AtomicChange.cpp clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp clang/lib/Tooling/Syntax/Tokens.cpp Removed: ################################################################################ diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h index c9ab8c949a4cb6a..82a26356c58f556 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchers.h +++ b/clang/include/clang/ASTMatchers/ASTMatchers.h @@ -300,7 +300,7 @@ AST_POLYMORPHIC_MATCHER_REGEX(isExpansionInFileMatching, return false; } auto FileEntry = - SourceManager.getFileEntryForID(SourceManager.getFileID(ExpansionLoc)); + SourceManager.getFileEntryRefForID(SourceManager.getFileID(ExpansionLoc)); if (!FileEntry) { return false; } diff --git a/clang/include/clang/Basic/SourceLocation.h b/clang/include/clang/Basic/SourceLocation.h index c709c1102834bff..ad0682511f97d47 100644 --- a/clang/include/clang/Basic/SourceLocation.h +++ b/clang/include/clang/Basic/SourceLocation.h @@ -14,6 +14,7 @@ #ifndef LLVM_CLANG_BASIC_SOURCELOCATION_H #define LLVM_CLANG_BASIC_SOURCELOCATION_H +#include "clang/Basic/FileEntry.h" #include "clang/Basic/LLVM.h" #include "llvm/ADT/StringRef.h" #include <cassert> @@ -356,8 +357,6 @@ class PresumedLoc { } }; -class FileEntry; - /// A SourceLocation and its associated SourceManager. /// /// This is useful for argument passing to functions that expect both objects. @@ -413,6 +412,7 @@ class FullSourceLoc : public SourceLocation { unsigned getColumnNumber(bool *Invalid = nullptr) const; const FileEntry *getFileEntry() const; + OptionalFileEntryRef getFileEntryRef() const; /// Return a StringRef to the source buffer data for the /// specified FileID. diff --git a/clang/lib/ARCMigrate/ARCMT.cpp b/clang/lib/ARCMigrate/ARCMT.cpp index 84c73393178924d..8e398977dcd65d6 100644 --- a/clang/lib/ARCMigrate/ARCMT.cpp +++ b/clang/lib/ARCMigrate/ARCMT.cpp @@ -597,7 +597,8 @@ bool MigrationProcess::applyTransform(TransformFn trans, I = rewriter.buffer_begin(), E = rewriter.buffer_end(); I != E; ++I) { FileID FID = I->first; RewriteBuffer &buf = I->second; - const FileEntry *file = Ctx.getSourceManager().getFileEntryForID(FID); + OptionalFileEntryRef file = + Ctx.getSourceManager().getFileEntryRefForID(FID); assert(file); std::string newFname = std::string(file->getName()); newFname += "-trans"; diff --git a/clang/lib/ARCMigrate/ObjCMT.cpp b/clang/lib/ARCMigrate/ObjCMT.cpp index c76efd78976af39..8458a72d6a2482b 100644 --- a/clang/lib/ARCMigrate/ObjCMT.cpp +++ b/clang/lib/ARCMigrate/ObjCMT.cpp @@ -1785,7 +1785,7 @@ class JSONEditWriter : public edit::EditsReceiver { std::tie(FID, Offset) = SourceMgr.getDecomposedLoc(Loc); assert(FID.isValid()); SmallString<200> Path = - StringRef(SourceMgr.getFileEntryForID(FID)->getName()); + StringRef(SourceMgr.getFileEntryRefForID(FID)->getName()); llvm::sys::fs::make_absolute(Path); OS << " \"file\": \""; OS.write_escaped(Path.str()) << "\",\n"; diff --git a/clang/lib/ARCMigrate/PlistReporter.cpp b/clang/lib/ARCMigrate/PlistReporter.cpp index c233d6bd9002a98..f78ca5e1c9bdd9a 100644 --- a/clang/lib/ARCMigrate/PlistReporter.cpp +++ b/clang/lib/ARCMigrate/PlistReporter.cpp @@ -72,7 +72,7 @@ void arcmt::writeARCDiagsToPlist(const std::string &outPath, " <array>\n"; for (FileID FID : Fids) - EmitString(o << " ", SM.getFileEntryForID(FID)->getName()) << '\n'; + EmitString(o << " ", SM.getFileEntryRefForID(FID)->getName()) << '\n'; o << " </array>\n" " <key>diagnostics</key>\n" diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp index 91af18d61197967..79175c79de96bf8 100644 --- a/clang/lib/AST/MicrosoftMangle.cpp +++ b/clang/lib/AST/MicrosoftMangle.cpp @@ -483,7 +483,7 @@ MicrosoftMangleContextImpl::MicrosoftMangleContextImpl(ASTContext &Context, // The generated names are intended to look similar to what MSVC generates, // which are something like "?A0x01234567@". SourceManager &SM = Context.getSourceManager(); - if (const FileEntry *FE = SM.getFileEntryForID(SM.getMainFileID())) { + if (OptionalFileEntryRef FE = SM.getFileEntryRefForID(SM.getMainFileID())) { // Truncate the hash so we get 8 characters of hexadecimal. uint32_t TruncatedHash = uint32_t(xxh3_64bits(FE->getName())); AnonymousNamespaceHash = llvm::utohexstr(TruncatedHash); diff --git a/clang/lib/Analysis/PathDiagnostic.cpp b/clang/lib/Analysis/PathDiagnostic.cpp index 93e6d98492ddef9..348afc42319e575 100644 --- a/clang/lib/Analysis/PathDiagnostic.cpp +++ b/clang/lib/Analysis/PathDiagnostic.cpp @@ -336,8 +336,10 @@ static bool compareCrossTUSourceLocs(FullSourceLoc XL, FullSourceLoc YL) { std::pair<bool, bool> InSameTU = SM.isInTheSameTranslationUnit(XOffs, YOffs); if (InSameTU.first) return XL.isBeforeInTranslationUnitThan(YL); - const FileEntry *XFE = SM.getFileEntryForID(XL.getSpellingLoc().getFileID()); - const FileEntry *YFE = SM.getFileEntryForID(YL.getSpellingLoc().getFileID()); + OptionalFileEntryRef XFE = + SM.getFileEntryRefForID(XL.getSpellingLoc().getFileID()); + OptionalFileEntryRef YFE = + SM.getFileEntryRefForID(YL.getSpellingLoc().getFileID()); if (!XFE || !YFE) return XFE && !YFE; int NameCmp = XFE->getName().compare(YFE->getName()); diff --git a/clang/lib/Basic/SourceLocation.cpp b/clang/lib/Basic/SourceLocation.cpp index 772f2e612f0747d..37baf643a0a9018 100644 --- a/clang/lib/Basic/SourceLocation.cpp +++ b/clang/lib/Basic/SourceLocation.cpp @@ -227,6 +227,11 @@ const FileEntry *FullSourceLoc::getFileEntry() const { return SrcMgr->getFileEntryForID(getFileID()); } +OptionalFileEntryRef FullSourceLoc::getFileEntryRef() const { + assert(isValid()); + return SrcMgr->getFileEntryRefForID(getFileID()); +} + unsigned FullSourceLoc::getExpansionLineNumber(bool *Invalid) const { assert(isValid()); return SrcMgr->getExpansionLineNumber(*this, Invalid); diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index 6fa802a33a503b8..b8a9fb7fc16f7a1 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -1018,7 +1018,7 @@ SourceLocation SourceManager::getImmediateSpellingLoc(SourceLocation Loc) const{ /// Return the filename of the file containing a SourceLocation. StringRef SourceManager::getFilename(SourceLocation SpellingLoc) const { - if (const FileEntry *F = getFileEntryForID(getFileID(SpellingLoc))) + if (OptionalFileEntryRef F = getFileEntryRefForID(getFileID(SpellingLoc))) return F->getName(); return StringRef(); } diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index f5513217bebfbaa..8b0c9340775cbe9 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -3215,7 +3215,7 @@ bool CodeGenModule::isInNoSanitizeList(SanitizerMask Kind, llvm::Function *Fn, return true; // NoSanitize by location. Check "mainfile" prefix. auto &SM = Context.getSourceManager(); - const FileEntry &MainFile = *SM.getFileEntryForID(SM.getMainFileID()); + FileEntryRef MainFile = *SM.getFileEntryRefForID(SM.getMainFileID()); if (NoSanitizeL.containsMainFile(Kind, MainFile.getName())) return true; @@ -3236,7 +3236,8 @@ bool CodeGenModule::isInNoSanitizeList(SanitizerMask Kind, return true; auto &SM = Context.getSourceManager(); if (NoSanitizeL.containsMainFile( - Kind, SM.getFileEntryForID(SM.getMainFileID())->getName(), Category)) + Kind, SM.getFileEntryRefForID(SM.getMainFileID())->getName(), + Category)) return true; if (NoSanitizeL.containsLocation(Kind, Loc, Category)) return true; @@ -3302,7 +3303,7 @@ CodeGenModule::isFunctionBlockedByProfileList(llvm::Function *Fn, // If location is unknown, this may be a compiler-generated function. Assume // it's located in the main file. auto &SM = Context.getSourceManager(); - if (const auto *MainFile = SM.getFileEntryForID(SM.getMainFileID())) + if (auto MainFile = SM.getFileEntryRefForID(SM.getMainFileID())) if (auto V = ProfileList.isFileExcluded(MainFile->getName(), Kind)) return *V; return ProfileList.getDefault(Kind); diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index 167db521a890cd9..016f88a43a56ddd 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -1497,8 +1497,8 @@ StringRef ASTUnit::getMainFileName() const { } if (SourceMgr) { - if (const FileEntry * - FE = SourceMgr->getFileEntryForID(SourceMgr->getMainFileID())) + if (OptionalFileEntryRef FE = + SourceMgr->getFileEntryRefForID(SourceMgr->getMainFileID())) return FE->getName(); } diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp index e016b941963c1c6..7912ff0a144bf08 100644 --- a/clang/lib/Frontend/FrontendAction.cpp +++ b/clang/lib/Frontend/FrontendAction.cpp @@ -666,7 +666,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, } else { auto &OldSM = AST->getSourceManager(); FileID ID = OldSM.getMainFileID(); - if (auto *File = OldSM.getFileEntryForID(ID)) + if (auto File = OldSM.getFileEntryRefForID(ID)) Input = FrontendInputFile(File->getName(), Kind); else Input = FrontendInputFile(OldSM.getBufferOrFake(ID), Kind); @@ -844,7 +844,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, return false; } // We now have the filename... - FileName = FE->getFileEntry().getName(); + FileName = FE->getName(); // ... still a header unit, but now use the path as written. Kind = Input.getKind().withHeaderUnit(InputKind::HeaderUnit_Abs); Input = FrontendInputFile(FileName, Kind, Input.isSystem()); diff --git a/clang/lib/Frontend/HeaderIncludeGen.cpp b/clang/lib/Frontend/HeaderIncludeGen.cpp index 9c1bf490fcd65e1..992c2670260e50c 100644 --- a/clang/lib/Frontend/HeaderIncludeGen.cpp +++ b/clang/lib/Frontend/HeaderIncludeGen.cpp @@ -259,7 +259,7 @@ void HeaderIncludesCallback::FileSkipped(const FileEntryRef &SkippedFile, const } void HeaderIncludesJSONCallback::EndOfMainFile() { - const FileEntry *FE = SM.getFileEntryForID(SM.getMainFileID()); + OptionalFileEntryRef FE = SM.getFileEntryRefForID(SM.getMainFileID()); SmallString<256> MainFile(FE->getName()); SM.getFileManager().makeAbsolutePath(MainFile); diff --git a/clang/lib/Frontend/LogDiagnosticPrinter.cpp b/clang/lib/Frontend/LogDiagnosticPrinter.cpp index d810b37ca57f29a..32fc6cb2acd8756 100644 --- a/clang/lib/Frontend/LogDiagnosticPrinter.cpp +++ b/clang/lib/Frontend/LogDiagnosticPrinter.cpp @@ -118,7 +118,7 @@ void LogDiagnosticPrinter::HandleDiagnostic(DiagnosticsEngine::Level Level, const SourceManager &SM = Info.getSourceManager(); FileID FID = SM.getMainFileID(); if (FID.isValid()) { - if (const FileEntry *FE = SM.getFileEntryForID(FID)) + if (OptionalFileEntryRef FE = SM.getFileEntryRefForID(FID)) MainFilename = std::string(FE->getName()); } } @@ -147,7 +147,7 @@ void LogDiagnosticPrinter::HandleDiagnostic(DiagnosticsEngine::Level Level, // At least print the file name if available: FileID FID = SM.getFileID(Info.getLocation()); if (FID.isValid()) { - if (const FileEntry *FE = SM.getFileEntryForID(FID)) + if (OptionalFileEntryRef FE = SM.getFileEntryRefForID(FID)) DE.Filename = std::string(FE->getName()); } } else { diff --git a/clang/lib/Frontend/PrecompiledPreamble.cpp b/clang/lib/Frontend/PrecompiledPreamble.cpp index b768c53198a05a0..62373b23b82efbd 100644 --- a/clang/lib/Frontend/PrecompiledPreamble.cpp +++ b/clang/lib/Frontend/PrecompiledPreamble.cpp @@ -550,19 +550,19 @@ llvm::ErrorOr<PrecompiledPreamble> PrecompiledPreamble::Build( SourceManager &SourceMgr = Clang->getSourceManager(); for (auto &Filename : PreambleDepCollector->getDependencies()) { - auto FileOrErr = Clang->getFileManager().getFile(Filename); - if (!FileOrErr || - *FileOrErr == SourceMgr.getFileEntryForID(SourceMgr.getMainFileID())) + auto MaybeFile = Clang->getFileManager().getOptionalFileRef(Filename); + if (!MaybeFile || + MaybeFile == SourceMgr.getFileEntryRefForID(SourceMgr.getMainFileID())) continue; - auto File = *FileOrErr; - if (time_t ModTime = File->getModificationTime()) { - FilesInPreamble[File->getName()] = - PrecompiledPreamble::PreambleFileHash::createForFile(File->getSize(), + auto File = *MaybeFile; + if (time_t ModTime = File.getModificationTime()) { + FilesInPreamble[File.getName()] = + PrecompiledPreamble::PreambleFileHash::createForFile(File.getSize(), ModTime); } else { llvm::MemoryBufferRef Buffer = SourceMgr.getMemoryBufferForFileOrFake(File); - FilesInPreamble[File->getName()] = + FilesInPreamble[File.getName()] = PrecompiledPreamble::PreambleFileHash::createForMemoryBuffer(Buffer); } } diff --git a/clang/lib/Frontend/Rewrite/FixItRewriter.cpp b/clang/lib/Frontend/Rewrite/FixItRewriter.cpp index 4fe64b96cb15048..567bac576adb40a 100644 --- a/clang/lib/Frontend/Rewrite/FixItRewriter.cpp +++ b/clang/lib/Frontend/Rewrite/FixItRewriter.cpp @@ -93,7 +93,8 @@ bool FixItRewriter::WriteFixedFiles( } for (iterator I = buffer_begin(), E = buffer_end(); I != E; ++I) { - const FileEntry *Entry = Rewrite.getSourceMgr().getFileEntryForID(I->first); + OptionalFileEntryRef Entry = + Rewrite.getSourceMgr().getFileEntryRefForID(I->first); int fd; std::string Filename = FixItOpts->RewriteFilename(std::string(Entry->getName()), fd); diff --git a/clang/lib/Frontend/Rewrite/HTMLPrint.cpp b/clang/lib/Frontend/Rewrite/HTMLPrint.cpp index 1388c2e1faab2b5..69baa8f591088c9 100644 --- a/clang/lib/Frontend/Rewrite/HTMLPrint.cpp +++ b/clang/lib/Frontend/Rewrite/HTMLPrint.cpp @@ -62,7 +62,7 @@ void HTMLPrinter::HandleTranslationUnit(ASTContext &Ctx) { // Format the file. FileID FID = R.getSourceMgr().getMainFileID(); - const FileEntry* Entry = R.getSourceMgr().getFileEntryForID(FID); + OptionalFileEntryRef Entry = R.getSourceMgr().getFileEntryRefForID(FID); StringRef Name; // In some cases, in particular the case where the input is from stdin, // there is no entry. Fall back to the memory buffer for a name in those diff --git a/clang/lib/Frontend/SARIFDiagnostic.cpp b/clang/lib/Frontend/SARIFDiagnostic.cpp index 416e9132afaf5c8..ee8e8b54e512c49 100644 --- a/clang/lib/Frontend/SARIFDiagnostic.cpp +++ b/clang/lib/Frontend/SARIFDiagnostic.cpp @@ -70,7 +70,7 @@ SarifResult SARIFDiagnostic::addLocationToResult( // At least add the file name if available: FileID FID = Loc.getFileID(); if (FID.isValid()) { - if (const FileEntry *FE = Loc.getFileEntry()) { + if (OptionalFileEntryRef FE = Loc.getFileEntryRef()) { emitFilename(FE->getName(), Loc.getManager()); // FIXME(llvm-project/issues/57366): File-only locations } diff --git a/clang/lib/Frontend/TextDiagnostic.cpp b/clang/lib/Frontend/TextDiagnostic.cpp index 1b58261b22a2653..7f558541a28711b 100644 --- a/clang/lib/Frontend/TextDiagnostic.cpp +++ b/clang/lib/Frontend/TextDiagnostic.cpp @@ -779,7 +779,7 @@ void TextDiagnostic::emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc, if (PLoc.isInvalid()) { // At least print the file name if available: if (FileID FID = Loc.getFileID(); FID.isValid()) { - if (const FileEntry *FE = Loc.getFileEntry()) { + if (OptionalFileEntryRef FE = Loc.getFileEntryRef()) { emitFilename(FE->getName(), Loc.getManager()); OS << ": "; } diff --git a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp index c811db86611e036..d70f2a90a629ce1 100644 --- a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp +++ b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp @@ -868,8 +868,8 @@ static unsigned PrintUnexpected(DiagnosticsEngine &Diags, SourceManager *SourceM OS << "\n (frontend)"; else { OS << "\n "; - if (const FileEntry *File = SourceMgr->getFileEntryForID( - SourceMgr->getFileID(I->first))) + if (OptionalFileEntryRef File = + SourceMgr->getFileEntryRefForID(SourceMgr->getFileID(I->first))) OS << " File " << File->getName(); OS << " Line " << SourceMgr->getPresumedLineNumber(I->first); } diff --git a/clang/lib/Index/CommentToXML.cpp b/clang/lib/Index/CommentToXML.cpp index 1cbd14cd326c4dc..f599e83aeca7093 100644 --- a/clang/lib/Index/CommentToXML.cpp +++ b/clang/lib/Index/CommentToXML.cpp @@ -891,7 +891,7 @@ void CommentASTToXMLConverter::visitFullComment(const FullComment *C) { unsigned FileOffset = LocInfo.second; if (FID.isValid()) { - if (const FileEntry *FE = SM.getFileEntryForID(FID)) { + if (OptionalFileEntryRef FE = SM.getFileEntryRefForID(FID)) { Result << " file=\""; appendToResultWithXMLEscaping(FE->getName()); Result << "\""; diff --git a/clang/lib/Index/USRGeneration.cpp b/clang/lib/Index/USRGeneration.cpp index b10028a526ed584..f778a6208d5122d 100644 --- a/clang/lib/Index/USRGeneration.cpp +++ b/clang/lib/Index/USRGeneration.cpp @@ -31,7 +31,7 @@ static bool printLoc(llvm::raw_ostream &OS, SourceLocation Loc, } Loc = SM.getExpansionLoc(Loc); const std::pair<FileID, unsigned> &Decomposed = SM.getDecomposedLoc(Loc); - const FileEntry *FE = SM.getFileEntryForID(Decomposed.first); + OptionalFileEntryRef FE = SM.getFileEntryRefForID(Decomposed.first); if (FE) { OS << llvm::sys::path::filename(FE->getName()); } else { diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index b8c2d4a95854975..a401017d4c1c0b8 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -152,9 +152,9 @@ class SemaPPCallbacks : public PPCallbacks { SourceLocation IncludeLoc = SM.getIncludeLoc(SM.getFileID(Loc)); if (IncludeLoc.isValid()) { if (llvm::timeTraceProfilerEnabled()) { - const FileEntry *FE = SM.getFileEntryForID(SM.getFileID(Loc)); - llvm::timeTraceProfilerBegin( - "Source", FE != nullptr ? FE->getName() : StringRef("<unknown>")); + OptionalFileEntryRef FE = SM.getFileEntryRefForID(SM.getFileID(Loc)); + llvm::timeTraceProfilerBegin("Source", FE ? FE->getName() + : StringRef("<unknown>")); } IncludeStack.push_back(IncludeLoc); diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp index 9b8af60a93d1021..f8fc27188824eb5 100644 --- a/clang/lib/Sema/SemaModule.cpp +++ b/clang/lib/Sema/SemaModule.cpp @@ -103,7 +103,8 @@ void Sema::HandleStartOfHeaderUnit() { StringRef HUName = getLangOpts().CurrentModule; if (HUName.empty()) { - HUName = SourceMgr.getFileEntryForID(SourceMgr.getMainFileID())->getName(); + HUName = + SourceMgr.getFileEntryRefForID(SourceMgr.getMainFileID())->getName(); const_cast<LangOptions &>(getLangOpts()).CurrentModule = HUName.str(); } diff --git a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp index f91a51cc5f8f6ab..69d25120dcd43bf 100644 --- a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp +++ b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp @@ -112,7 +112,7 @@ class HTMLDiagnostics : public PathDiagnosticConsumer { // Add HTML header/footers to file specified by FID void FinalizeHTML(const PathDiagnostic &D, Rewriter &R, const SourceManager &SMgr, const PathPieces &path, - FileID FID, const FileEntry *Entry, const char *declName); + FileID FID, FileEntryRef Entry, const char *declName); // Rewrite the file specified by FID with HTML formatting. void RewriteFile(Rewriter &R, const PathPieces &path, FileID FID); @@ -326,7 +326,7 @@ void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D, FileID ReportFile = path.back()->getLocation().asLocation().getExpansionLoc().getFileID(); - const FileEntry *Entry = SMgr.getFileEntryForID(ReportFile); + OptionalFileEntryRef Entry = SMgr.getFileEntryRefForID(ReportFile); FileName << llvm::sys::path::filename(Entry->getName()).str() << "-" << declName.c_str() << "-" << offsetDecl << "-"; @@ -396,7 +396,7 @@ std::string HTMLDiagnostics::GenerateHTML(const PathDiagnostic& D, Rewriter &R, os << "<div class=FileNav><a href=\"#File" << (I - 1)->getHashValue() << "\">←</a></div>"; - os << "<h4 class=FileName>" << SMgr.getFileEntryForID(*I)->getName() + os << "<h4 class=FileName>" << SMgr.getFileEntryRefForID(*I)->getName() << "</h4>\n"; // Right nav arrow @@ -429,8 +429,8 @@ std::string HTMLDiagnostics::GenerateHTML(const PathDiagnostic& D, Rewriter &R, // Add CSS, header, and footer. FileID FID = path.back()->getLocation().asLocation().getExpansionLoc().getFileID(); - const FileEntry* Entry = SMgr.getFileEntryForID(FID); - FinalizeHTML(D, R, SMgr, path, FileIDs[0], Entry, declName); + OptionalFileEntryRef Entry = SMgr.getFileEntryRefForID(FID); + FinalizeHTML(D, R, SMgr, path, FileIDs[0], *Entry, declName); std::string file; llvm::raw_string_ostream os(file); @@ -537,16 +537,17 @@ document.addEventListener("DOMContentLoaded", function() { return s; } -void HTMLDiagnostics::FinalizeHTML(const PathDiagnostic& D, Rewriter &R, - const SourceManager& SMgr, const PathPieces& path, FileID FID, - const FileEntry *Entry, const char *declName) { +void HTMLDiagnostics::FinalizeHTML(const PathDiagnostic &D, Rewriter &R, + const SourceManager &SMgr, + const PathPieces &path, FileID FID, + FileEntryRef Entry, const char *declName) { // This is a cludge; basically we want to append either the full // working directory if we have no directory information. This is // a work in progress. llvm::SmallString<0> DirName; - if (llvm::sys::path::is_relative(Entry->getName())) { + if (llvm::sys::path::is_relative(Entry.getName())) { llvm::sys::fs::current_path(DirName); DirName += '/'; } @@ -575,7 +576,7 @@ void HTMLDiagnostics::FinalizeHTML(const PathDiagnostic& D, Rewriter &R, << "<h3>Bug Summary</h3>\n<table class=\"simpletable\">\n" "<tr><td class=\"rowname\">File:</td><td>" << html::EscapeText(DirName) - << html::EscapeText(Entry->getName()) + << html::EscapeText(Entry.getName()) << "</td></tr>\n<tr><td class=\"rowname\">Warning:</td><td>" "<a href=\"#EndPath\">line " << LineNumber @@ -656,9 +657,9 @@ void HTMLDiagnostics::FinalizeHTML(const PathDiagnostic& D, Rewriter &R, if (!BugCategory.empty()) os << "\n<!-- BUGCATEGORY " << BugCategory << " -->\n"; - os << "\n<!-- BUGFILE " << DirName << Entry->getName() << " -->\n"; + os << "\n<!-- BUGFILE " << DirName << Entry.getName() << " -->\n"; - os << "\n<!-- FILENAME " << llvm::sys::path::filename(Entry->getName()) << " -->\n"; + os << "\n<!-- FILENAME " << llvm::sys::path::filename(Entry.getName()) << " -->\n"; os << "\n<!-- FUNCTIONNAME " << declName << " -->\n"; @@ -682,7 +683,7 @@ void HTMLDiagnostics::FinalizeHTML(const PathDiagnostic& D, Rewriter &R, R.InsertTextBefore(SMgr.getLocForStartOfFile(FID), os.str()); } - html::AddHeaderFooterInternalBuiltinCSS(R, FID, Entry->getName()); + html::AddHeaderFooterInternalBuiltinCSS(R, FID, Entry.getName()); } StringRef HTMLDiagnostics::showHelpJavascript() { diff --git a/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp b/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp index bdf485364cef309..be19a1c118ea5ab 100644 --- a/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp +++ b/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp @@ -804,7 +804,7 @@ void PlistDiagnostics::FlushDiagnosticsImpl( o << " <key>files</key>\n" " <array>\n"; for (FileID FID : Fids) - EmitString(o << " ", SM.getFileEntryForID(FID)->getName()) << '\n'; + EmitString(o << " ", SM.getFileEntryRefForID(FID)->getName()) << '\n'; o << " </array>\n"; if (llvm::AreStatisticsEnabled() && DiagOpts.ShouldSerializeStats) { diff --git a/clang/lib/Tooling/Core/Replacement.cpp b/clang/lib/Tooling/Core/Replacement.cpp index 020ad08a65e7ec7..2c472df086d5ec5 100644 --- a/clang/lib/Tooling/Core/Replacement.cpp +++ b/clang/lib/Tooling/Core/Replacement.cpp @@ -122,7 +122,8 @@ void Replacement::setFromSourceLocation(const SourceManager &Sources, StringRef ReplacementText) { const std::pair<FileID, unsigned> DecomposedLocation = Sources.getDecomposedLoc(Start); - const FileEntry *Entry = Sources.getFileEntryForID(DecomposedLocation.first); + OptionalFileEntryRef Entry = + Sources.getFileEntryRefForID(DecomposedLocation.first); this->FilePath = std::string(Entry ? Entry->getName() : InvalidLocation); this->ReplacementRange = Range(DecomposedLocation.second, Length); this->ReplacementText = std::string(ReplacementText); diff --git a/clang/lib/Tooling/Refactoring/AtomicChange.cpp b/clang/lib/Tooling/Refactoring/AtomicChange.cpp index 069e9c1eb36ef97..7237393f00e57e2 100644 --- a/clang/lib/Tooling/Refactoring/AtomicChange.cpp +++ b/clang/lib/Tooling/Refactoring/AtomicChange.cpp @@ -198,7 +198,7 @@ AtomicChange::AtomicChange(const SourceManager &SM, const FullSourceLoc FullKeyPosition(KeyPosition, SM); std::pair<FileID, unsigned> FileIDAndOffset = FullKeyPosition.getSpellingLoc().getDecomposedLoc(); - const FileEntry *FE = SM.getFileEntryForID(FileIDAndOffset.first); + OptionalFileEntryRef FE = SM.getFileEntryRefForID(FileIDAndOffset.first); assert(FE && "Cannot create AtomicChange with invalid location."); FilePath = std::string(FE->getName()); Key = FilePath + ":" + std::to_string(FileIDAndOffset.second); diff --git a/clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp b/clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp index de11263efd5aaad..7708fea53d014c6 100644 --- a/clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp +++ b/clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp @@ -243,7 +243,8 @@ class NamedDeclFindingConsumer : public ASTConsumer { DiagnosticsEngine::Error, "SourceLocation in file %0 at offset %1 is invalid"); Engine.Report(SourceLocation(), InvalidOffset) - << SourceMgr.getFileEntryForID(MainFileID)->getName() << SymbolOffset; + << SourceMgr.getFileEntryRefForID(MainFileID)->getName() + << SymbolOffset; return false; } diff --git a/clang/lib/Tooling/Syntax/Tokens.cpp b/clang/lib/Tooling/Syntax/Tokens.cpp index baf9d76b0ba05fe..2f28b9cf286a638 100644 --- a/clang/lib/Tooling/Syntax/Tokens.cpp +++ b/clang/lib/Tooling/Syntax/Tokens.cpp @@ -940,7 +940,7 @@ std::string TokenBuffer::dumpForTests() const { for (FileID ID : Keys) { const MarkedFile &File = Files.find(ID)->second; - auto *Entry = SourceMgr->getFileEntryForID(ID); + auto Entry = SourceMgr->getFileEntryRefForID(ID); if (!Entry) continue; // Skip builtin files. std::string Path = llvm::sys::path::convert_to_slash(Entry->getName()); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits