Skip to content

Commit 77148fc

Browse files
authored
[clang] Do not share ownership of HeaderSearchOptions (#132984)
This PR makes it so that `CompilerInvocation` is the sole owner of the `HeaderSearchOptions` instance.
1 parent 09b012f commit 77148fc

File tree

11 files changed

+12
-21
lines changed

11 files changed

+12
-21
lines changed

clang/include/clang/Frontend/ASTUnit.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class ASTUnit {
116116
std::shared_ptr<Preprocessor> PP;
117117
IntrusiveRefCntPtr<ASTContext> Ctx;
118118
std::shared_ptr<TargetOptions> TargetOpts;
119-
std::shared_ptr<HeaderSearchOptions> HSOpts;
119+
std::unique_ptr<HeaderSearchOptions> HSOpts;
120120
std::shared_ptr<PreprocessorOptions> PPOpts;
121121
IntrusiveRefCntPtr<ASTReader> Reader;
122122
bool HadModuleLoaderFatalFailure = false;
@@ -699,7 +699,7 @@ class ASTUnit {
699699
WhatToLoad ToLoad,
700700
IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
701701
const FileSystemOptions &FileSystemOpts,
702-
std::shared_ptr<HeaderSearchOptions> HSOpts,
702+
const HeaderSearchOptions &HSOpts,
703703
std::shared_ptr<LangOptions> LangOpts = nullptr,
704704
bool OnlyLocalDecls = false,
705705
CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None,

clang/include/clang/Frontend/CompilerInstance.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,6 @@ class CompilerInstance : public ModuleLoader {
316316
const HeaderSearchOptions &getHeaderSearchOpts() const {
317317
return Invocation->getHeaderSearchOpts();
318318
}
319-
std::shared_ptr<HeaderSearchOptions> getHeaderSearchOptsPtr() const {
320-
return Invocation->getHeaderSearchOptsPtr();
321-
}
322319

323320
APINotesOptions &getAPINotesOpts() { return Invocation->getAPINotesOpts(); }
324321
const APINotesOptions &getAPINotesOpts() const {

clang/include/clang/Frontend/CompilerInvocation.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,6 @@ class CompilerInvocation : public CompilerInvocationBase {
269269
/// @{
270270
using CompilerInvocationBase::LangOpts;
271271
using CompilerInvocationBase::TargetOpts;
272-
std::shared_ptr<HeaderSearchOptions> getHeaderSearchOptsPtr() {
273-
return HSOpts;
274-
}
275272
std::shared_ptr<LangOptions> getLangOptsPtr() { return LangOpts; }
276273
/// @}
277274

clang/lib/CrossTU/CrossTranslationUnit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ CrossTranslationUnitContext::ASTLoader::loadFromDump(StringRef ASTDumpPath) {
569569
return ASTUnit::LoadFromASTFile(
570570
ASTDumpPath, CI.getPCHContainerOperations()->getRawReader(),
571571
ASTUnit::LoadEverything, Diags, CI.getFileSystemOpts(),
572-
CI.getHeaderSearchOptsPtr());
572+
CI.getHeaderSearchOpts());
573573
}
574574

575575
/// Load the AST from a source-file, which is supposed to be located inside the

clang/lib/Frontend/ASTMerge.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void ASTMergeAction::ExecuteAction() {
4848
/*ShouldOwnClient=*/true));
4949
std::unique_ptr<ASTUnit> Unit = ASTUnit::LoadFromASTFile(
5050
ASTFiles[I], CI.getPCHContainerReader(), ASTUnit::LoadEverything, Diags,
51-
CI.getFileSystemOpts(), CI.getHeaderSearchOptsPtr());
51+
CI.getFileSystemOpts(), CI.getHeaderSearchOpts());
5252

5353
if (!Unit)
5454
continue;

clang/lib/Frontend/ASTUnit.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -804,8 +804,7 @@ void ASTUnit::ConfigureDiags(IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
804804
std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile(
805805
StringRef Filename, const PCHContainerReader &PCHContainerRdr,
806806
WhatToLoad ToLoad, IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
807-
const FileSystemOptions &FileSystemOpts,
808-
std::shared_ptr<HeaderSearchOptions> HSOpts,
807+
const FileSystemOptions &FileSystemOpts, const HeaderSearchOptions &HSOpts,
809808
std::shared_ptr<LangOptions> LangOpts, bool OnlyLocalDecls,
810809
CaptureDiagsKind CaptureDiagnostics, bool AllowASTWithCompilerErrors,
811810
bool UserFilesAreVolatile, IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) {
@@ -830,7 +829,7 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile(
830829
AST->getFileManager(),
831830
UserFilesAreVolatile);
832831
AST->ModCache = createCrossProcessModuleCache();
833-
AST->HSOpts = HSOpts ? HSOpts : std::make_shared<HeaderSearchOptions>();
832+
AST->HSOpts = std::make_unique<HeaderSearchOptions>(HSOpts);
834833
AST->HSOpts->ModuleFormat = std::string(PCHContainerRdr.getFormats().front());
835834
AST->HeaderInfo.reset(new HeaderSearch(AST->getHeaderSearchOpts(),
836835
AST->getSourceManager(),

clang/lib/Frontend/FrontendAction.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -780,8 +780,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
780780

781781
std::unique_ptr<ASTUnit> AST = ASTUnit::LoadFromASTFile(
782782
InputFile, CI.getPCHContainerReader(), ASTUnit::LoadPreprocessorOnly,
783-
ASTDiags, CI.getFileSystemOpts(),
784-
/*HeaderSearchOptions=*/nullptr);
783+
ASTDiags, CI.getFileSystemOpts(), CI.getHeaderSearchOpts());
785784
if (!AST)
786785
return false;
787786

@@ -848,8 +847,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
848847

849848
std::unique_ptr<ASTUnit> AST = ASTUnit::LoadFromASTFile(
850849
InputFile, CI.getPCHContainerReader(), ASTUnit::LoadEverything, Diags,
851-
CI.getFileSystemOpts(), CI.getHeaderSearchOptsPtr(),
852-
CI.getLangOptsPtr());
850+
CI.getFileSystemOpts(), CI.getHeaderSearchOpts(), CI.getLangOptsPtr());
853851

854852
if (!AST)
855853
return false;

clang/tools/c-index-test/core_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ static bool printSourceSymbolsFromModule(StringRef modulePath,
272272
return true;
273273
}
274274

275-
auto HSOpts = std::make_shared<HeaderSearchOptions>();
275+
HeaderSearchOptions HSOpts;
276276

277277
IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
278278
CompilerInstance::createDiagnostics(*llvm::vfs::getRealFileSystem(),

clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ static bool HandleAST(StringRef AstPath) {
157157
std::unique_ptr<ASTUnit> Unit = ASTUnit::LoadFromASTFile(
158158
AstPath, CI->getPCHContainerOperations()->getRawReader(),
159159
ASTUnit::LoadASTOnly, DiagEngine, CI->getFileSystemOpts(),
160-
CI->getHeaderSearchOptsPtr());
160+
CI->getHeaderSearchOpts());
161161

162162
if (!Unit)
163163
return false;

clang/tools/libclang/CIndex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4225,7 +4225,7 @@ enum CXErrorCode clang_createTranslationUnit2(CXIndex CIdx,
42254225

42264226
CIndexer *CXXIdx = static_cast<CIndexer *>(CIdx);
42274227
FileSystemOptions FileSystemOpts;
4228-
auto HSOpts = std::make_shared<HeaderSearchOptions>();
4228+
HeaderSearchOptions HSOpts;
42294229

42304230
IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
42314231
CompilerInstance::createDiagnostics(*llvm::vfs::getRealFileSystem(),

0 commit comments

Comments
 (0)