[clang] [clang] Make `HeaderSearchOptions` references const (PR #130825)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 11 13:23:57 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Jan Svoboda (jansvoboda11)
<details>
<summary>Changes</summary>
This PR makes the `HeaderSearchOptions` object referenced by `HeaderSearch` constant. Depends on #<!-- -->130823.
---
Full diff: https://github.com/llvm/llvm-project/pull/130825.diff
5 Files Affected:
- (modified) clang/include/clang/Lex/HeaderSearch.h (+3-3)
- (modified) clang/lib/Frontend/CompilerInstance.cpp (+2-1)
- (modified) clang/lib/Frontend/FrontendActions.cpp (+2-1)
- (modified) clang/lib/Lex/HeaderSearch.cpp (+1-1)
- (modified) clang/lib/Serialization/ASTReader.cpp (+2-1)
``````````diff
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 6098e2e30af9d..b9a1303e4876d 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -632,7 +632,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, ModuleCache, &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 d0a1a9221ce6f..9b6cdb02d9389 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -4897,7 +4897,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
``````````
</details>
https://github.com/llvm/llvm-project/pull/130825
More information about the cfe-commits
mailing list