Author: Jan Svoboda Date: 2025-03-21T14:39:50-07:00 New Revision: 72e596f35951e849de9fc739238e84ec1217b939
URL: https://github.com/llvm/llvm-project/commit/72e596f35951e849de9fc739238e84ec1217b939 DIFF: https://github.com/llvm/llvm-project/commit/72e596f35951e849de9fc739238e84ec1217b939.diff LOG: [clang] Make `HeaderSearchOptions` references const (#130825) This PR makes the `HeaderSearchOptions` object referenced by `HeaderSearch` constant. Depends on #130823. Added: Modified: clang/include/clang/Lex/HeaderSearch.h clang/lib/Frontend/CompilerInstance.cpp clang/lib/Frontend/FrontendActions.cpp clang/lib/Lex/HeaderSearch.cpp clang/lib/Serialization/ASTReader.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Lex/HeaderSearch.h b/clang/include/clang/Lex/HeaderSearch.h index a10adae17998b..f3dac905318c6 100644 --- a/clang/include/clang/Lex/HeaderSearch.h +++ b/clang/include/clang/Lex/HeaderSearch.h @@ -241,7 +241,7 @@ class HeaderSearch { friend SearchDirIterator; /// Header-search options used to initialize this header search. - std::shared_ptr<HeaderSearchOptions> HSOpts; + std::shared_ptr<const HeaderSearchOptions> HSOpts; /// Mapping from SearchDir to HeaderSearchOptions::UserEntries indices. llvm::DenseMap<unsigned, unsigned> SearchDirToHSEntry; @@ -359,7 +359,7 @@ class HeaderSearch { void indexInitialHeaderMaps(); public: - HeaderSearch(std::shared_ptr<HeaderSearchOptions> HSOpts, + HeaderSearch(std::shared_ptr<const HeaderSearchOptions> HSOpts, SourceManager &SourceMgr, DiagnosticsEngine &Diags, const LangOptions &LangOpts, const TargetInfo *Target); HeaderSearch(const HeaderSearch &) = delete; @@ -367,7 +367,7 @@ class HeaderSearch { /// Retrieve the header-search options with which this header search /// was initialized. - HeaderSearchOptions &getHeaderSearchOpts() const { return *HSOpts; } + const HeaderSearchOptions &getHeaderSearchOpts() const { return *HSOpts; } FileManager &getFileMgr() const { return FileMgr; } diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 02994bce8b335..bff5326e89973 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -631,7 +631,8 @@ IntrusiveRefCntPtr<ASTReader> CompilerInstance::createPCHExternalASTSource( ArrayRef<std::shared_ptr<DependencyCollector>> DependencyCollectors, void *DeserializationListener, bool OwnDeserializationListener, bool Preamble, bool UseGlobalModuleIndex) { - HeaderSearchOptions &HSOpts = PP.getHeaderSearchInfo().getHeaderSearchOpts(); + const HeaderSearchOptions &HSOpts = + PP.getHeaderSearchInfo().getHeaderSearchOpts(); IntrusiveRefCntPtr<ASTReader> Reader(new ASTReader( PP, ModCache, &Context, PCHContainerRdr, Extensions, diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp index 1ea4a2e9e88cf..bf273c82a96e8 100644 --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -878,7 +878,8 @@ void DumpModuleInfoAction::ExecuteAction() { Preprocessor &PP = CI.getPreprocessor(); DumpModuleInfoListener Listener(Out); - HeaderSearchOptions &HSOpts = PP.getHeaderSearchInfo().getHeaderSearchOpts(); + const HeaderSearchOptions &HSOpts = + PP.getHeaderSearchInfo().getHeaderSearchOpts(); // The FrontendAction::BeginSourceFile () method loads the AST so that much // of the information is already available and modules should have been diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp index 6fc477dff43ad..ad9263f2994f2 100644 --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -80,7 +80,7 @@ HeaderFileInfo::getControllingMacro(ExternalPreprocessorSource *External) { ExternalHeaderFileInfoSource::~ExternalHeaderFileInfoSource() = default; -HeaderSearch::HeaderSearch(std::shared_ptr<HeaderSearchOptions> HSOpts, +HeaderSearch::HeaderSearch(std::shared_ptr<const HeaderSearchOptions> HSOpts, SourceManager &SourceMgr, DiagnosticsEngine &Diags, const LangOptions &LangOpts, const TargetInfo *Target) diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 46a84bbfaaaef..2728e93c69516 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -4901,7 +4901,8 @@ ASTReader::ASTReadResult ASTReader::ReadAST(StringRef FileName, ModuleKind Type, } } - HeaderSearchOptions &HSOpts = PP.getHeaderSearchInfo().getHeaderSearchOpts(); + const HeaderSearchOptions &HSOpts = + PP.getHeaderSearchInfo().getHeaderSearchOpts(); if (HSOpts.ModulesValidateOncePerBuildSession) { // Now we are certain that the module and all modules it depends on are // up-to-date. For implicitly-built module files, ensure the corresponding _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits