ParseAST now never releases the passed ASTConsumer. This is the responsibility of the client.
The motivation is that clients may either:
(a) query the ASTConsumer object after AST parsing to collect data/etc.
(b) reuse the ASTConsumer.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54502 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Driver/clang.cpp b/Driver/clang.cpp
index 28ec5ff..8bafbd5 100644
--- a/Driver/clang.cpp
+++ b/Driver/clang.cpp
@@ -1228,14 +1228,14 @@
static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF,
const std::string &InFile) {
- ASTConsumer* Consumer = NULL;
+ llvm::OwningPtr<ASTConsumer> Consumer;
bool ClearSourceMgr = false;
switch (ProgAction) {
default:
- Consumer = CreateASTConsumer(InFile, PP.getDiagnostics(),
- PP.getFileManager(), PP.getLangOptions(), &PP,
- &PPF);
+ Consumer.reset(CreateASTConsumer(InFile, PP.getDiagnostics(),
+ PP.getFileManager(), PP.getLangOptions(),
+ &PP, &PPF));
if (!Consumer) {
fprintf(stderr, "Unexpected program action!\n");
@@ -1283,7 +1283,7 @@
break;
case ParseSyntaxOnly: // -fsyntax-only
- Consumer = new ASTConsumer();
+ Consumer.reset(new ASTConsumer());
break;
case RewriteMacros:
@@ -1294,10 +1294,9 @@
if (Consumer) {
if (VerifyDiagnostics)
- exit(CheckASTConsumer(PP, Consumer));
+ exit(CheckASTConsumer(PP, Consumer.get()));
- // This deletes Consumer.
- ParseAST(PP, Consumer, Stats);
+ ParseAST(PP, Consumer.get(), Stats);
}
if (Stats) {