From: Daniel Dunbar Date: Wed, 29 Jul 2009 02:40:09 +0000 (+0000) Subject: Destroy the ASTConsumer prior to the Context, HTMLPrinter for example wants to X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=70186ab134119fbec816a02596e29fb4cfbe51e1;p=clang Destroy the ASTConsumer prior to the Context, HTMLPrinter for example wants to do a significant amount of work in its destructor, which may access the context. (PR4642). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77423 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp index bb18a998b2..ab4bb1eff4 100644 --- a/tools/clang-cc/clang-cc.cpp +++ b/tools/clang-cc/clang-cc.cpp @@ -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();