/// CompilerInvocation object.
///
/// \param CI - The compiler invocation to use; it must have exactly one input
- /// source file. The caller is responsible for ensuring the lifetime of the
- /// invocation extends past that of the returned ASTUnit.
+ /// source file. The ASTUnit takes ownership of the CompilerInvocation object.
///
/// \param Diags - The diagnostics engine to use for reporting errors; its
/// lifetime is expected to extend past that of the returned ASTUnit.
//
// FIXME: Move OnlyLocalDecls, UseBumpAllocator to setters on the ASTUnit, we
// shouldn't need to specify them at construction time.
- static ASTUnit *LoadFromCompilerInvocation(const CompilerInvocation &CI,
+ static ASTUnit *LoadFromCompilerInvocation(CompilerInvocation *CI,
Diagnostic &Diags,
bool OnlyLocalDecls = false);
}
-ASTUnit *ASTUnit::LoadFromCompilerInvocation(const CompilerInvocation &CI,
+ASTUnit *ASTUnit::LoadFromCompilerInvocation(CompilerInvocation *CI,
Diagnostic &Diags,
bool OnlyLocalDecls) {
// Create the compiler instance to use for building the AST.
llvm::OwningPtr<ASTUnit> AST;
llvm::OwningPtr<TopLevelDeclTrackerAction> Act;
- Clang.setInvocation(const_cast<CompilerInvocation*>(&CI));
+ Clang.setInvocation(CI);
Clang.setDiagnostics(&Diags);
Clang.setDiagnosticClient(Diags.getClient());
Clang.takeDiagnostics();
Clang.takeInvocation();
+ AST->Invocation.reset(Clang.takeInvocation());
return AST.take();
error:
CI->getHeaderSearchOpts().ResourceDir = ResourceFilesPath;
CI->getFrontendOpts().DisableFree = UseBumpAllocator;
- ASTUnit *Unit = LoadFromCompilerInvocation(*CI, Diags, OnlyLocalDecls);
- if (Unit)
- Unit->Invocation.reset(CI.take());
-
- return Unit;
+ return LoadFromCompilerInvocation(CI.take(), Diags, OnlyLocalDecls);
}