[cfe-commits] r99258 - /cfe/trunk/tools/driver/cc1_main.cpp

Daniel Dunbar daniel at zuster.org
Mon Mar 22 22:09:16 PDT 2010


Author: ddunbar
Date: Tue Mar 23 00:09:16 2010
New Revision: 99258

URL: http://llvm.org/viewvc/llvm-project?rev=99258&view=rev
Log:
Frontend: Don't free the CompilerInstance or FrontendActions when running under
-disable-free. Among other things, this fixes freeing of the LLVM module on
exit.
 - Note that this means we are disable-free'ing of a lot more stuff than we used to -- this should flush out bugs in anything left that is trying to do real work in its destructor. I did a mini-audit but '::~' is not totally uncommon.

Modified:
    cfe/trunk/tools/driver/cc1_main.cpp

Modified: cfe/trunk/tools/driver/cc1_main.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/cc1_main.cpp?rev=99258&r1=99257&r2=99258&view=diff
==============================================================================
--- cfe/trunk/tools/driver/cc1_main.cpp (original)
+++ cfe/trunk/tools/driver/cc1_main.cpp Tue Mar 23 00:09:16 2010
@@ -195,9 +195,9 @@
 
 int cc1_main(const char **ArgBegin, const char **ArgEnd,
              const char *Argv0, void *MainAddr) {
-  CompilerInstance Clang;
+  llvm::OwningPtr<CompilerInstance> Clang(new CompilerInstance());
 
-  Clang.setLLVMContext(new llvm::LLVMContext);
+  Clang->setLLVMContext(new llvm::LLVMContext);
 
   // Run clang -cc1 test.
   if (ArgBegin != ArgEnd && llvm::StringRef(ArgBegin[0]) == "-cc1test") {
@@ -214,17 +214,17 @@
   // well formed diagnostic object.
   TextDiagnosticBuffer DiagsBuffer;
   Diagnostic Diags(&DiagsBuffer);
-  CompilerInvocation::CreateFromArgs(Clang.getInvocation(), ArgBegin, ArgEnd,
+  CompilerInvocation::CreateFromArgs(Clang->getInvocation(), ArgBegin, ArgEnd,
                                      Diags);
 
   // Infer the builtin include path if unspecified.
-  if (Clang.getHeaderSearchOpts().UseBuiltinIncludes &&
-      Clang.getHeaderSearchOpts().ResourceDir.empty())
-    Clang.getHeaderSearchOpts().ResourceDir =
+  if (Clang->getHeaderSearchOpts().UseBuiltinIncludes &&
+      Clang->getHeaderSearchOpts().ResourceDir.empty())
+    Clang->getHeaderSearchOpts().ResourceDir =
       CompilerInvocation::GetResourcesPath(Argv0, MainAddr);
 
   // Honor -help.
-  if (Clang.getFrontendOpts().ShowHelp) {
+  if (Clang->getFrontendOpts().ShowHelp) {
     llvm::OwningPtr<driver::OptTable> Opts(driver::createCC1OptTable());
     Opts->PrintHelp(llvm::outs(), "clang -cc1",
                     "LLVM 'Clang' Compiler: http://clang.llvm.org");
@@ -234,27 +234,27 @@
   // Honor -version.
   //
   // FIXME: Use a better -version message?
-  if (Clang.getFrontendOpts().ShowVersion) {
+  if (Clang->getFrontendOpts().ShowVersion) {
     llvm::cl::PrintVersionMessage();
     return 0;
   }
 
   // Create the actual diagnostics engine.
-  Clang.createDiagnostics(ArgEnd - ArgBegin, const_cast<char**>(ArgBegin));
-  if (!Clang.hasDiagnostics())
+  Clang->createDiagnostics(ArgEnd - ArgBegin, const_cast<char**>(ArgBegin));
+  if (!Clang->hasDiagnostics())
     return 1;
 
   // Set an error handler, so that any LLVM backend diagnostics go through our
   // error handler.
   llvm::llvm_install_error_handler(LLVMErrorHandler,
-                                   static_cast<void*>(&Clang.getDiagnostics()));
+                                  static_cast<void*>(&Clang->getDiagnostics()));
 
-  DiagsBuffer.FlushDiagnostics(Clang.getDiagnostics());
+  DiagsBuffer.FlushDiagnostics(Clang->getDiagnostics());
 
   // Load any requested plugins.
   for (unsigned i = 0,
-         e = Clang.getFrontendOpts().Plugins.size(); i != e; ++i) {
-    const std::string &Path = Clang.getFrontendOpts().Plugins[i];
+         e = Clang->getFrontendOpts().Plugins.size(); i != e; ++i) {
+    const std::string &Path = Clang->getFrontendOpts().Plugins[i];
     std::string Error;
     if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(Path.c_str(), &Error))
       Diags.Report(diag::err_fe_unable_to_load_plugin) << Path << Error;
@@ -262,11 +262,20 @@
 
   // If there were errors in processing arguments, don't do anything else.
   bool Success = false;
-  if (!Clang.getDiagnostics().getNumErrors()) {
+  if (!Clang->getDiagnostics().getNumErrors()) {
     // Create and execute the frontend action.
-    llvm::OwningPtr<FrontendAction> Act(CreateFrontendAction(Clang));
-    if (Act)
-      Success = Clang.ExecuteAction(*Act);
+    llvm::OwningPtr<FrontendAction> Act(CreateFrontendAction(*Clang));
+    if (Act) {
+      Success = Clang->ExecuteAction(*Act);
+      if (Clang->getFrontendOpts().DisableFree)
+        Act.take();
+    }
+  }
+
+  // When running with -disable-free, don't do any destruction or shutdown.
+  if (Clang->getFrontendOpts().DisableFree) {
+    Clang.take();
+    return !Success;
   }
 
   // Managed static deconstruction. Useful for making things like





More information about the cfe-commits mailing list