Destroy the ASTConsumer prior to the Context, HTMLPrinter for example wants to
authorDaniel Dunbar <daniel@zuster.org>
Wed, 29 Jul 2009 02:40:09 +0000 (02:40 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Wed, 29 Jul 2009 02:40:09 +0000 (02:40 +0000)
do a significant amount of work in its destructor, which may access the
context. (PR4642).

llvm-svn: 77423

clang/tools/clang-cc/clang-cc.cpp

index bb18a99..ab4bb1e 100644 (file)
@@ -2078,6 +2078,13 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF,
   
   if (FixItRewrite)
     FixItRewrite->WriteFixedFile(InFile, OutputFile);
+
+  // Disable the consumer prior to the context, the consumer may perform actions
+  // in its destructor which require the context.
+  if (DisableFree)
+    Consumer.take();
+  else
+    Consumer.reset();
   
   // If in -disable-free mode, don't deallocate ASTContext.
   if (DisableFree)
@@ -2104,11 +2111,6 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF,
   if (ClearSourceMgr)
     PP.getSourceManager().clearIDTables();
 
-  if (DisableFree)
-    Consumer.take();
-  else
-    Consumer.reset();
-
   // Always delete the output stream because we don't want to leak file
   // handles.  Also, we don't want to try to erase an open file.
   OS.reset();