From 7db4f60b2654c10835dea950dce71f6206d04a2e Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Thu, 7 Aug 2008 19:47:41 +0000 Subject: [PATCH] ParseAST now conditionally deletes the passed ASTConsumer. ModuleBuilder now performs llvmgen in HandleTranslationUnit. This patch follows from the discussion on the following thread on cfe-commits: http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20080804/006849.html llvm-svn: 54486 --- clang/include/clang/Sema/ParseAST.h | 2 +- clang/lib/CodeGen/ModuleBuilder.cpp | 19 +++++++++++-------- clang/lib/Sema/ParseAST.cpp | 5 +++-- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/clang/include/clang/Sema/ParseAST.h b/clang/include/clang/Sema/ParseAST.h index 61ce30d9f4ee..9f6690a0bdc7 100644 --- a/clang/include/clang/Sema/ParseAST.h +++ b/clang/include/clang/Sema/ParseAST.h @@ -21,7 +21,7 @@ namespace clang { /// ParseAST - Parse the entire file specified, notifying the ASTConsumer as /// the file is parsed. This takes ownership of the ASTConsumer and /// ultimately deletes it. - void ParseAST(Preprocessor &pp, ASTConsumer *C, bool PrintStats = false); + void ParseAST(Preprocessor &pp, ASTConsumer *C, bool PrintStats = false, bool DeleteConsumer = true); } // end namespace clang #endif diff --git a/clang/lib/CodeGen/ModuleBuilder.cpp b/clang/lib/CodeGen/ModuleBuilder.cpp index 7329ed1d90d0..6ce4e6894d94 100644 --- a/clang/lib/CodeGen/ModuleBuilder.cpp +++ b/clang/lib/CodeGen/ModuleBuilder.cpp @@ -49,13 +49,7 @@ namespace { virtual ~CodeGeneratorImpl() {} - virtual llvm::Module* ReleaseModule() { - if (Diags.hasErrorOccurred()) - return 0; - - if (Builder) - Builder->Release(); - + virtual llvm::Module* ReleaseModule() { return M.take(); } @@ -134,7 +128,16 @@ namespace { virtual void HandleTagDeclDefinition(TagDecl *D) { Builder->UpdateCompletedType(D); } - + + virtual void HandleTranslationUnit(TranslationUnit& TU) { + if (Diags.hasErrorOccurred()) { + M.reset(); + return; + } + + if (Builder) + Builder->Release(); + }; }; } diff --git a/clang/lib/Sema/ParseAST.cpp b/clang/lib/Sema/ParseAST.cpp index 94e0185f03f9..6b9b8d5804dd 100644 --- a/clang/lib/Sema/ParseAST.cpp +++ b/clang/lib/Sema/ParseAST.cpp @@ -27,7 +27,7 @@ using namespace clang; /// ParseAST - Parse the entire file specified, notifying the ASTConsumer as /// the file is parsed. This takes ownership of the ASTConsumer and /// ultimately deletes it. -void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer, bool PrintStats) { +void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer, bool PrintStats, bool DeleteConsumer) { // Collect global stats on Decls/Stmts (until we have a module streamer). if (PrintStats) { Decl::CollectingStats(true); @@ -78,5 +78,6 @@ void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer, bool PrintStats) { Stmt::CollectingStats(false); } - delete Consumer; + if (DeleteConsumer) + delete Consumer; }