Skip to content

Commit 72e596f

Browse files
authored
[clang] Make HeaderSearchOptions references const (#130825)
This PR makes the `HeaderSearchOptions` object referenced by `HeaderSearch` constant. Depends on #130823.
1 parent 896df5c commit 72e596f

File tree

5 files changed

+10
-7
lines changed

5 files changed

+10
-7
lines changed

clang/include/clang/Lex/HeaderSearch.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ class HeaderSearch {
241241
friend SearchDirIterator;
242242

243243
/// Header-search options used to initialize this header search.
244-
std::shared_ptr<HeaderSearchOptions> HSOpts;
244+
std::shared_ptr<const HeaderSearchOptions> HSOpts;
245245

246246
/// Mapping from SearchDir to HeaderSearchOptions::UserEntries indices.
247247
llvm::DenseMap<unsigned, unsigned> SearchDirToHSEntry;
@@ -359,15 +359,15 @@ class HeaderSearch {
359359
void indexInitialHeaderMaps();
360360

361361
public:
362-
HeaderSearch(std::shared_ptr<HeaderSearchOptions> HSOpts,
362+
HeaderSearch(std::shared_ptr<const HeaderSearchOptions> HSOpts,
363363
SourceManager &SourceMgr, DiagnosticsEngine &Diags,
364364
const LangOptions &LangOpts, const TargetInfo *Target);
365365
HeaderSearch(const HeaderSearch &) = delete;
366366
HeaderSearch &operator=(const HeaderSearch &) = delete;
367367

368368
/// Retrieve the header-search options with which this header search
369369
/// was initialized.
370-
HeaderSearchOptions &getHeaderSearchOpts() const { return *HSOpts; }
370+
const HeaderSearchOptions &getHeaderSearchOpts() const { return *HSOpts; }
371371

372372
FileManager &getFileMgr() const { return FileMgr; }
373373

clang/lib/Frontend/CompilerInstance.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,8 @@ IntrusiveRefCntPtr<ASTReader> CompilerInstance::createPCHExternalASTSource(
631631
ArrayRef<std::shared_ptr<DependencyCollector>> DependencyCollectors,
632632
void *DeserializationListener, bool OwnDeserializationListener,
633633
bool Preamble, bool UseGlobalModuleIndex) {
634-
HeaderSearchOptions &HSOpts = PP.getHeaderSearchInfo().getHeaderSearchOpts();
634+
const HeaderSearchOptions &HSOpts =
635+
PP.getHeaderSearchInfo().getHeaderSearchOpts();
635636

636637
IntrusiveRefCntPtr<ASTReader> Reader(new ASTReader(
637638
PP, ModCache, &Context, PCHContainerRdr, Extensions,

clang/lib/Frontend/FrontendActions.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,8 @@ void DumpModuleInfoAction::ExecuteAction() {
878878

879879
Preprocessor &PP = CI.getPreprocessor();
880880
DumpModuleInfoListener Listener(Out);
881-
HeaderSearchOptions &HSOpts = PP.getHeaderSearchInfo().getHeaderSearchOpts();
881+
const HeaderSearchOptions &HSOpts =
882+
PP.getHeaderSearchInfo().getHeaderSearchOpts();
882883

883884
// The FrontendAction::BeginSourceFile () method loads the AST so that much
884885
// of the information is already available and modules should have been

clang/lib/Lex/HeaderSearch.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ HeaderFileInfo::getControllingMacro(ExternalPreprocessorSource *External) {
8080

8181
ExternalHeaderFileInfoSource::~ExternalHeaderFileInfoSource() = default;
8282

83-
HeaderSearch::HeaderSearch(std::shared_ptr<HeaderSearchOptions> HSOpts,
83+
HeaderSearch::HeaderSearch(std::shared_ptr<const HeaderSearchOptions> HSOpts,
8484
SourceManager &SourceMgr, DiagnosticsEngine &Diags,
8585
const LangOptions &LangOpts,
8686
const TargetInfo *Target)

clang/lib/Serialization/ASTReader.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -4901,7 +4901,8 @@ ASTReader::ASTReadResult ASTReader::ReadAST(StringRef FileName, ModuleKind Type,
49014901
}
49024902
}
49034903

4904-
HeaderSearchOptions &HSOpts = PP.getHeaderSearchInfo().getHeaderSearchOpts();
4904+
const HeaderSearchOptions &HSOpts =
4905+
PP.getHeaderSearchInfo().getHeaderSearchOpts();
49054906
if (HSOpts.ModulesValidateOncePerBuildSession) {
49064907
// Now we are certain that the module and all modules it depends on are
49074908
// up-to-date. For implicitly-built module files, ensure the corresponding

0 commit comments

Comments
 (0)