llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Jan Svoboda (jansvoboda11) <details> <summary>Changes</summary> This PR makes it so that `CompilerInvocation` is the sole owner of the `HeaderSearchOptions` instance. --- Full diff: https://github.com/llvm/llvm-project/pull/132984.diff 11 Files Affected: - (modified) clang/include/clang/Frontend/ASTUnit.h (+2-2) - (modified) clang/include/clang/Frontend/CompilerInstance.h (-3) - (modified) clang/include/clang/Frontend/CompilerInvocation.h (-3) - (modified) clang/lib/CrossTU/CrossTranslationUnit.cpp (+1-1) - (modified) clang/lib/Frontend/ASTMerge.cpp (+1-1) - (modified) clang/lib/Frontend/ASTUnit.cpp (+2-2) - (modified) clang/lib/Frontend/FrontendAction.cpp (+2-4) - (modified) clang/tools/c-index-test/core_main.cpp (+1-1) - (modified) clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp (+1-1) - (modified) clang/tools/libclang/CIndex.cpp (+1-1) - (modified) clang/unittests/Frontend/ASTUnitTest.cpp (+1-1) ``````````diff diff --git a/clang/include/clang/Frontend/ASTUnit.h b/clang/include/clang/Frontend/ASTUnit.h index 0506ac361721d..eadc4f3719ba4 100644 --- a/clang/include/clang/Frontend/ASTUnit.h +++ b/clang/include/clang/Frontend/ASTUnit.h @@ -116,7 +116,7 @@ class ASTUnit { std::shared_ptr<Preprocessor> PP; IntrusiveRefCntPtr<ASTContext> Ctx; std::shared_ptr<TargetOptions> TargetOpts; - std::shared_ptr<HeaderSearchOptions> HSOpts; + std::unique_ptr<HeaderSearchOptions> HSOpts; std::shared_ptr<PreprocessorOptions> PPOpts; IntrusiveRefCntPtr<ASTReader> Reader; bool HadModuleLoaderFatalFailure = false; @@ -699,7 +699,7 @@ class ASTUnit { WhatToLoad ToLoad, IntrusiveRefCntPtr<DiagnosticsEngine> Diags, const FileSystemOptions &FileSystemOpts, - std::shared_ptr<HeaderSearchOptions> HSOpts, + const HeaderSearchOptions &HSOpts, std::shared_ptr<LangOptions> LangOpts = nullptr, bool OnlyLocalDecls = false, CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None, diff --git a/clang/include/clang/Frontend/CompilerInstance.h b/clang/include/clang/Frontend/CompilerInstance.h index 4960d40ca7c37..56977e99c8b8b 100644 --- a/clang/include/clang/Frontend/CompilerInstance.h +++ b/clang/include/clang/Frontend/CompilerInstance.h @@ -322,9 +322,6 @@ class CompilerInstance : public ModuleLoader { const HeaderSearchOptions &getHeaderSearchOpts() const { return Invocation->getHeaderSearchOpts(); } - std::shared_ptr<HeaderSearchOptions> getHeaderSearchOptsPtr() const { - return Invocation->getHeaderSearchOptsPtr(); - } APINotesOptions &getAPINotesOpts() { return Invocation->getAPINotesOpts(); } const APINotesOptions &getAPINotesOpts() const { diff --git a/clang/include/clang/Frontend/CompilerInvocation.h b/clang/include/clang/Frontend/CompilerInvocation.h index 1e4d2da86c2be..890744ff3f6f9 100644 --- a/clang/include/clang/Frontend/CompilerInvocation.h +++ b/clang/include/clang/Frontend/CompilerInvocation.h @@ -269,9 +269,6 @@ class CompilerInvocation : public CompilerInvocationBase { /// @{ using CompilerInvocationBase::LangOpts; using CompilerInvocationBase::TargetOpts; - std::shared_ptr<HeaderSearchOptions> getHeaderSearchOptsPtr() { - return HSOpts; - } std::shared_ptr<PreprocessorOptions> getPreprocessorOptsPtr() { return PPOpts; } diff --git a/clang/lib/CrossTU/CrossTranslationUnit.cpp b/clang/lib/CrossTU/CrossTranslationUnit.cpp index ad2ebb6cd6e6c..ef395f497216c 100644 --- a/clang/lib/CrossTU/CrossTranslationUnit.cpp +++ b/clang/lib/CrossTU/CrossTranslationUnit.cpp @@ -569,7 +569,7 @@ CrossTranslationUnitContext::ASTLoader::loadFromDump(StringRef ASTDumpPath) { return ASTUnit::LoadFromASTFile( ASTDumpPath, CI.getPCHContainerOperations()->getRawReader(), ASTUnit::LoadEverything, Diags, CI.getFileSystemOpts(), - CI.getHeaderSearchOptsPtr()); + CI.getHeaderSearchOpts()); } /// Load the AST from a source-file, which is supposed to be located inside the diff --git a/clang/lib/Frontend/ASTMerge.cpp b/clang/lib/Frontend/ASTMerge.cpp index 1e3a5c04c4e9b..b6b06440bc3f8 100644 --- a/clang/lib/Frontend/ASTMerge.cpp +++ b/clang/lib/Frontend/ASTMerge.cpp @@ -48,7 +48,7 @@ void ASTMergeAction::ExecuteAction() { /*ShouldOwnClient=*/true)); std::unique_ptr<ASTUnit> Unit = ASTUnit::LoadFromASTFile( ASTFiles[I], CI.getPCHContainerReader(), ASTUnit::LoadEverything, Diags, - CI.getFileSystemOpts(), CI.getHeaderSearchOptsPtr()); + CI.getFileSystemOpts(), CI.getHeaderSearchOpts()); if (!Unit) continue; diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index 0a5f1cfd1a264..4f78569c7c7c0 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -805,7 +805,7 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile( StringRef Filename, const PCHContainerReader &PCHContainerRdr, WhatToLoad ToLoad, IntrusiveRefCntPtr<DiagnosticsEngine> Diags, const FileSystemOptions &FileSystemOpts, - std::shared_ptr<HeaderSearchOptions> HSOpts, + const HeaderSearchOptions &HSOpts, std::shared_ptr<LangOptions> LangOpts, bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics, bool AllowASTWithCompilerErrors, bool UserFilesAreVolatile, IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) { @@ -830,7 +830,7 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile( AST->getFileManager(), UserFilesAreVolatile); AST->ModCache = createCrossProcessModuleCache(); - AST->HSOpts = HSOpts ? HSOpts : std::make_shared<HeaderSearchOptions>(); + AST->HSOpts = std::make_unique<HeaderSearchOptions>(HSOpts); AST->HSOpts->ModuleFormat = std::string(PCHContainerRdr.getFormats().front()); AST->HeaderInfo.reset(new HeaderSearch(AST->getHeaderSearchOpts(), AST->getSourceManager(), diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp index 9f789f093f55d..23013a0c99ca9 100644 --- a/clang/lib/Frontend/FrontendAction.cpp +++ b/clang/lib/Frontend/FrontendAction.cpp @@ -625,8 +625,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, std::unique_ptr<ASTUnit> AST = ASTUnit::LoadFromASTFile( InputFile, CI.getPCHContainerReader(), ASTUnit::LoadPreprocessorOnly, - ASTDiags, CI.getFileSystemOpts(), - /*HeaderSearchOptions=*/nullptr); + ASTDiags, CI.getFileSystemOpts(), CI.getHeaderSearchOpts()); if (!AST) return false; @@ -693,8 +692,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, std::unique_ptr<ASTUnit> AST = ASTUnit::LoadFromASTFile( InputFile, CI.getPCHContainerReader(), ASTUnit::LoadEverything, Diags, - CI.getFileSystemOpts(), CI.getHeaderSearchOptsPtr(), - CI.getLangOptsPtr()); + CI.getFileSystemOpts(), CI.getHeaderSearchOpts(), CI.getLangOptsPtr()); if (!AST) return false; diff --git a/clang/tools/c-index-test/core_main.cpp b/clang/tools/c-index-test/core_main.cpp index 327a77a09408b..8d023a0b22121 100644 --- a/clang/tools/c-index-test/core_main.cpp +++ b/clang/tools/c-index-test/core_main.cpp @@ -272,7 +272,7 @@ static bool printSourceSymbolsFromModule(StringRef modulePath, return true; } - auto HSOpts = std::make_shared<HeaderSearchOptions>(); + HeaderSearchOptions HSOpts; IntrusiveRefCntPtr<DiagnosticsEngine> Diags = CompilerInstance::createDiagnostics(*llvm::vfs::getRealFileSystem(), diff --git a/clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp b/clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp index 3a2c32cfa4684..ff684d20c150c 100644 --- a/clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp +++ b/clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp @@ -157,7 +157,7 @@ static bool HandleAST(StringRef AstPath) { std::unique_ptr<ASTUnit> Unit = ASTUnit::LoadFromASTFile( AstPath, CI->getPCHContainerOperations()->getRawReader(), ASTUnit::LoadASTOnly, DiagEngine, CI->getFileSystemOpts(), - CI->getHeaderSearchOptsPtr()); + CI->getHeaderSearchOpts()); if (!Unit) return false; diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index e498a875bbbe8..5a3211521f95a 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -4225,7 +4225,7 @@ enum CXErrorCode clang_createTranslationUnit2(CXIndex CIdx, CIndexer *CXXIdx = static_cast<CIndexer *>(CIdx); FileSystemOptions FileSystemOpts; - auto HSOpts = std::make_shared<HeaderSearchOptions>(); + HeaderSearchOptions HSOpts; IntrusiveRefCntPtr<DiagnosticsEngine> Diags = CompilerInstance::createDiagnostics(*llvm::vfs::getRealFileSystem(), diff --git a/clang/unittests/Frontend/ASTUnitTest.cpp b/clang/unittests/Frontend/ASTUnitTest.cpp index e6524a019871d..08daca9111e64 100644 --- a/clang/unittests/Frontend/ASTUnitTest.cpp +++ b/clang/unittests/Frontend/ASTUnitTest.cpp @@ -91,7 +91,7 @@ TEST_F(ASTUnitTest, SaveLoadPreservesLangOptionsInPrintingPolicy) { AST->Save(ASTFileName.str()); EXPECT_TRUE(llvm::sys::fs::exists(ASTFileName)); - auto HSOpts = std::make_shared<HeaderSearchOptions>(); + HeaderSearchOptions HSOpts; std::unique_ptr<ASTUnit> AU = ASTUnit::LoadFromASTFile( ASTFileName, PCHContainerOps->getRawReader(), ASTUnit::LoadEverything, `````````` </details> https://github.com/llvm/llvm-project/pull/132984 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits