aboutsummaryrefslogtreecommitdiff
path: root/tools/clang-cc/clang.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-03-28 01:37:17 +0000
committerChris Lattner <sabre@nondot.org>2009-03-28 01:37:17 +0000
commit9ecd26ad19875e410e76476b36f77c47069ba04c (patch)
tree80a3b71f18c04fa90f8d0636a4c1dfe816212a16 /tools/clang-cc/clang.cpp
parentab3a852ae713189444dcbf75e70accf1e8c2b7f2 (diff)
simplify ParseAST by sucking -disable-free handling logic up into
clang.cpp git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67890 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/clang-cc/clang.cpp')
-rw-r--r--tools/clang-cc/clang.cpp27
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)