]> granicus.if.org Git - clang/commitdiff
ASTUnit::LoadFromCompilerInvocation - Take ownership of the provided invocation.
authorDaniel Dunbar <daniel@zuster.org>
Tue, 16 Feb 2010 01:54:54 +0000 (01:54 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Tue, 16 Feb 2010 01:54:54 +0000 (01:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96315 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Frontend/ASTUnit.h
lib/Frontend/ASTUnit.cpp

index 7aeabe57ac002b6b484879de97b12c9c8c64ba54..56bc133afc5e4e22b04f2a77bc9d345ea01c06c3 100644 (file)
@@ -143,15 +143,14 @@ public:
   /// 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);
 
index 7f1e722f32c374e4366b8b7bcd3f1d3bf428d129..845b4cd5a69f5ef7619035618c4bbec804fef8a6 100644 (file)
@@ -230,7 +230,7 @@ public:
 
 }
 
-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.
@@ -238,7 +238,7 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocation(const CompilerInvocation &CI,
   llvm::OwningPtr<ASTUnit> AST;
   llvm::OwningPtr<TopLevelDeclTrackerAction> Act;
 
-  Clang.setInvocation(const_cast<CompilerInvocation*>(&CI));
+  Clang.setInvocation(CI);
 
   Clang.setDiagnostics(&Diags);
   Clang.setDiagnosticClient(Diags.getClient());
@@ -296,6 +296,7 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocation(const CompilerInvocation &CI,
   Clang.takeDiagnostics();
   Clang.takeInvocation();
 
+  AST->Invocation.reset(Clang.takeInvocation());
   return AST.take();
 
 error:
@@ -364,9 +365,5 @@ ASTUnit *ASTUnit::LoadFromCommandLine(const char **ArgBegin,
   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);
 }