diff options
Diffstat (limited to 'tools/clang-cc/clang.cpp')
-rw-r--r-- | tools/clang-cc/clang.cpp | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/tools/clang-cc/clang.cpp b/tools/clang-cc/clang.cpp index 5d3f68dd8e..3b2afa91a6 100644 --- a/tools/clang-cc/clang.cpp +++ b/tools/clang-cc/clang.cpp @@ -1476,17 +1476,26 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF, } if (Consumer) { - TranslationUnit *TU = 0; + llvm::OwningPtr<ASTContext> ContextOwner; + llvm::OwningPtr<TranslationUnit> TranslationUnitOwner; + + ContextOwner.reset(new ASTContext(PP.getLangOptions(), + PP.getSourceManager(), + PP.getTargetInfo(), + PP.getIdentifierTable(), + PP.getSelectorTable(), + /* FreeMemory = */ !DisableFree)); + TranslationUnitOwner.reset(new TranslationUnit(*ContextOwner.get())); + + + ParseAST(PP, Consumer.get(), *TranslationUnitOwner.get(), Stats); + + // If in -disable-free mode, don't deallocate these when they go out of + // scope. if (DisableFree) { - ASTContext *Context = new ASTContext(PP.getLangOptions(), - PP.getSourceManager(), - PP.getTargetInfo(), - PP.getIdentifierTable(), - PP.getSelectorTable(), - /* FreeMemory = */ false); - TU = new TranslationUnit(*Context); + ContextOwner.take(); + TranslationUnitOwner.take(); } - ParseAST(PP, Consumer.get(), TU, Stats); } if (VerifyDiagnostics) |