[cfe-commits] r96315 - in /cfe/trunk: include/clang/Frontend/ASTUnit.h lib/Frontend/ASTUnit.cpp

Daniel Dunbar daniel at zuster.org
Mon Feb 15 17:54:55 PST 2010


Author: ddunbar
Date: Mon Feb 15 19:54:54 2010
New Revision: 96315

URL: http://llvm.org/viewvc/llvm-project?rev=96315&view=rev
Log:
ASTUnit::LoadFromCompilerInvocation - Take ownership of the provided invocation.

Modified:
    cfe/trunk/include/clang/Frontend/ASTUnit.h
    cfe/trunk/lib/Frontend/ASTUnit.cpp

Modified: cfe/trunk/include/clang/Frontend/ASTUnit.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ASTUnit.h?rev=96315&r1=96314&r2=96315&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/ASTUnit.h (original)
+++ cfe/trunk/include/clang/Frontend/ASTUnit.h Mon Feb 15 19:54:54 2010
@@ -143,15 +143,14 @@
   /// 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);
 

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=96315&r1=96314&r2=96315&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Mon Feb 15 19:54:54 2010
@@ -230,7 +230,7 @@
 
 }
 
-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 @@
   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 @@
   Clang.takeDiagnostics();
   Clang.takeInvocation();
 
+  AST->Invocation.reset(Clang.takeInvocation());
   return AST.take();
 
 error:
@@ -364,9 +365,5 @@
   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);
 }





More information about the cfe-commits mailing list