summaryrefslogtreecommitdiffstats
path: root/clang/lib/Frontend/ASTUnit.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2010-01-30 21:47:16 +0000
committerDaniel Dunbar <daniel@zuster.org>2010-01-30 21:47:16 +0000
commit6b03ecef0dc25785fc4ff2051f60247e6ee75dbe (patch)
treecfb22442ac8f0a37530896796b9dd29a6d345d6a /clang/lib/Frontend/ASTUnit.cpp
parent682422546509c293b4d6236e3125ea747a9df7c8 (diff)
downloadbcm5719-llvm-6b03ecef0dc25785fc4ff2051f60247e6ee75dbe.tar.gz
bcm5719-llvm-6b03ecef0dc25785fc4ff2051f60247e6ee75dbe.zip
ASTUnit: Ensure the CompilerInvocation object used in LoadFromCommandLine is
live as long as the ASTUnit. This is useful for clients which want to maintain pointers to the LangOptions object which ultimately lives in the CompilerInvocation, although it would be nice to make all of this ownership stuff more explicit and obvious. llvm-svn: 94924
Diffstat (limited to 'clang/lib/Frontend/ASTUnit.cpp')
-rw-r--r--clang/lib/Frontend/ASTUnit.cpp19
1 files changed, 12 insertions, 7 deletions
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index eaa2062c862..7f1e722f32c 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -238,7 +238,7 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocation(const CompilerInvocation &CI,
llvm::OwningPtr<ASTUnit> AST;
llvm::OwningPtr<TopLevelDeclTrackerAction> Act;
- Clang.getInvocation() = CI;
+ Clang.setInvocation(const_cast<CompilerInvocation*>(&CI));
Clang.setDiagnostics(&Diags);
Clang.setDiagnosticClient(Diags.getClient());
@@ -294,6 +294,7 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocation(const CompilerInvocation &CI,
Clang.takeDiagnosticClient();
Clang.takeDiagnostics();
+ Clang.takeInvocation();
return AST.take();
@@ -349,19 +350,23 @@ ASTUnit *ASTUnit::LoadFromCommandLine(const char **ArgBegin,
}
const driver::ArgStringList &CCArgs = Cmd->getArguments();
- CompilerInvocation CI;
- CompilerInvocation::CreateFromArgs(CI, (const char**) CCArgs.data(),
+ llvm::OwningPtr<CompilerInvocation> CI(new CompilerInvocation);
+ CompilerInvocation::CreateFromArgs(*CI, (const char**) CCArgs.data(),
(const char**) CCArgs.data()+CCArgs.size(),
Diags);
// Override any files that need remapping
for (unsigned I = 0; I != NumRemappedFiles; ++I)
- CI.getPreprocessorOpts().addRemappedFile(RemappedFiles[I].first,
+ CI->getPreprocessorOpts().addRemappedFile(RemappedFiles[I].first,
RemappedFiles[I].second);
// Override the resources path.
- CI.getHeaderSearchOpts().ResourceDir = ResourceFilesPath;
+ CI->getHeaderSearchOpts().ResourceDir = ResourceFilesPath;
- CI.getFrontendOpts().DisableFree = UseBumpAllocator;
- return LoadFromCompilerInvocation(CI, Diags, OnlyLocalDecls);
+ CI->getFrontendOpts().DisableFree = UseBumpAllocator;
+ ASTUnit *Unit = LoadFromCompilerInvocation(*CI, Diags, OnlyLocalDecls);
+ if (Unit)
+ Unit->Invocation.reset(CI.take());
+
+ return Unit;
}
OpenPOWER on IntegriCloud