Skip to content

Commit 7b73dfc

Browse files
committed
[clang] Extend the lifetime of CompilerInvocation in ASTUnit::Parse()
1 parent e4c1f92 commit 7b73dfc

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
@@ -140,6 +140,10 @@ class ASTUnit {
140140
/// LoadFromCommandLine available.
141141
std::shared_ptr<CompilerInvocation> Invocation;
142142

143+
/// Optional owned invocation, just used to keep the invocation alive for the
144+
/// members initialized in transferASTDataFromCompilerInstance.
145+
std::shared_ptr<CompilerInvocation> ModifiedInvocation;
146+
143147
/// Fake module loader: the AST unit doesn't need to load any modules.
144148
TrivialModuleLoader ModuleLoader;
145149

clang/lib/Frontend/ASTUnit.cpp

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

15061510
StringRef ASTUnit::getMainFileName() const {

0 commit comments

Comments
 (0)