diff --git a/clang-tools-extra/clangd/IncludeCleaner.cpp b/clang-tools-extra/clangd/IncludeCleaner.cpp index d3ee7591edf09..a299347e8c0c3 100644 --- a/clang-tools-extra/clangd/IncludeCleaner.cpp +++ b/clang-tools-extra/clangd/IncludeCleaner.cpp @@ -390,7 +390,7 @@ IncludeCleanerFindings computeIncludeCleanerFindings(ParsedAST &AST) { const auto &SM = AST.getSourceManager(); include_cleaner::Includes ConvertedIncludes = convertIncludes(AST); const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID()); - auto *PreamblePatch = PreamblePatch::getPatchEntry(AST.tuPath(), SM); + auto PreamblePatch = PreamblePatch::getPatchEntry(AST.tuPath(), SM); std::vector Macros = collectMacroReferences(AST); diff --git a/clang-tools-extra/clangd/Preamble.cpp b/clang-tools-extra/clangd/Preamble.cpp index 60c0f936d6f38..8084e9644b426 100644 --- a/clang-tools-extra/clangd/Preamble.cpp +++ b/clang-tools-extra/clangd/Preamble.cpp @@ -953,12 +953,10 @@ const MainFileMacros &PreamblePatch::mainFileMacros() const { return PatchedMacros; } -const FileEntry *PreamblePatch::getPatchEntry(llvm::StringRef MainFilePath, - const SourceManager &SM) { +OptionalFileEntryRef PreamblePatch::getPatchEntry(llvm::StringRef MainFilePath, + const SourceManager &SM) { auto PatchFilePath = getPatchName(MainFilePath); - if (auto File = SM.getFileManager().getFile(PatchFilePath)) - return *File; - return nullptr; + return SM.getFileManager().getOptionalFileRef(PatchFilePath); } } // namespace clangd } // namespace clang diff --git a/clang-tools-extra/clangd/Preamble.h b/clang-tools-extra/clangd/Preamble.h index 21a281aac0cce..37da3833748a9 100644 --- a/clang-tools-extra/clangd/Preamble.h +++ b/clang-tools-extra/clangd/Preamble.h @@ -180,8 +180,8 @@ class PreamblePatch { const PreambleData &Baseline); /// Returns the FileEntry for the preamble patch of MainFilePath in SM, if /// any. - static const FileEntry *getPatchEntry(llvm::StringRef MainFilePath, - const SourceManager &SM); + static OptionalFileEntryRef getPatchEntry(llvm::StringRef MainFilePath, + const SourceManager &SM); /// Adjusts CI (which compiles the modified inputs) to be used with the /// baseline preamble. This is done by inserting an artificial include to the diff --git a/clang-tools-extra/clangd/unittests/PreambleTests.cpp b/clang-tools-extra/clangd/unittests/PreambleTests.cpp index 6da98c55e3927..3e9ed53043764 100644 --- a/clang-tools-extra/clangd/unittests/PreambleTests.cpp +++ b/clang-tools-extra/clangd/unittests/PreambleTests.cpp @@ -892,9 +892,9 @@ TEST(PreamblePatch, PatchFileEntry) { } { auto AST = createPatchedAST(Code.code(), NewCode.code()); - auto *FE = + auto FE = PreamblePatch::getPatchEntry(AST->tuPath(), AST->getSourceManager()); - ASSERT_NE(FE, nullptr); + ASSERT_NE(FE, std::nullopt); EXPECT_THAT(FE->getName().str(), testing::EndsWith(PreamblePatch::HeaderName.str())); }