Skip to content

Commit 84445a4

Browse files
committed
[clang] Extend the lifetime of CompilerInvocation in ASTUnit::Parse()
1 parent 4431265 commit 84445a4

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

clang/include/clang/Frontend/ASTUnit.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ class ASTUnit {
143143
/// Parse available.
144144
std::shared_ptr<CompilerInvocation> CCInvocation;
145145

146+
/// Optional owned invocation, just used to keep the invocation alive for the
147+
/// members initialized in transferASTDataFromCompilerInstance.
148+
std::shared_ptr<CompilerInvocation> ModifiedInvocation;
149+
146150
/// Fake module loader: the AST unit doesn't need to load any modules.
147151
TrivialModuleLoader ModuleLoader;
148152

clang/lib/Frontend/ASTUnit.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,6 +1499,10 @@ void ASTUnit::transferASTDataFromCompilerInstance(CompilerInstance &CI) {
14991499
Target = &CI.getTarget();
15001500
Reader = CI.getASTReader();
15011501
HadModuleLoaderFatalFailure = CI.hadModuleLoaderFatalFailure();
1502+
if (Invocation != CI.getInvocationPtr()) {
1503+
// This happens when Parse creates a copy of \c Invocation to modify.
1504+
ModifiedInvocation = CI.getInvocationPtr();
1505+
}
15021506
}
15031507

15041508
StringRef ASTUnit::getMainFileName() const {

0 commit comments

Comments
 (0)