Frontend: Don't free the CompilerInstance or FrontendActions when running under

-disable-free. Among other things, this fixes freeing of the LLVM module on
exit.
 - Note that this means we are disable-free'ing of a lot more stuff than we used to -- this should flush out bugs in anything left that is trying to do real work in its destructor. I did a mini-audit but '::~' is not totally uncommon.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99258 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Dunbar 2010-03-23 05:09:16 +00:00
Родитель dbd8209b33
Коммит 42444fb53c
1 изменённых файлов: 27 добавлений и 18 удалений

Просмотреть файл

@ -195,9 +195,9 @@ static int cc1_test(Diagnostic &Diags,
int cc1_main(const char **ArgBegin, const char **ArgEnd,
const char *Argv0, void *MainAddr) {
CompilerInstance Clang;
llvm::OwningPtr<CompilerInstance> Clang(new CompilerInstance());
Clang.setLLVMContext(new llvm::LLVMContext);
Clang->setLLVMContext(new llvm::LLVMContext);
// Run clang -cc1 test.
if (ArgBegin != ArgEnd && llvm::StringRef(ArgBegin[0]) == "-cc1test") {
@ -214,17 +214,17 @@ int cc1_main(const char **ArgBegin, const char **ArgEnd,
// well formed diagnostic object.
TextDiagnosticBuffer DiagsBuffer;
Diagnostic Diags(&DiagsBuffer);
CompilerInvocation::CreateFromArgs(Clang.getInvocation(), ArgBegin, ArgEnd,
CompilerInvocation::CreateFromArgs(Clang->getInvocation(), ArgBegin, ArgEnd,
Diags);
// Infer the builtin include path if unspecified.
if (Clang.getHeaderSearchOpts().UseBuiltinIncludes &&
Clang.getHeaderSearchOpts().ResourceDir.empty())
Clang.getHeaderSearchOpts().ResourceDir =
if (Clang->getHeaderSearchOpts().UseBuiltinIncludes &&
Clang->getHeaderSearchOpts().ResourceDir.empty())
Clang->getHeaderSearchOpts().ResourceDir =
CompilerInvocation::GetResourcesPath(Argv0, MainAddr);
// Honor -help.
if (Clang.getFrontendOpts().ShowHelp) {
if (Clang->getFrontendOpts().ShowHelp) {
llvm::OwningPtr<driver::OptTable> Opts(driver::createCC1OptTable());
Opts->PrintHelp(llvm::outs(), "clang -cc1",
"LLVM 'Clang' Compiler: http://clang.llvm.org");
@ -234,27 +234,27 @@ int cc1_main(const char **ArgBegin, const char **ArgEnd,
// Honor -version.
//
// FIXME: Use a better -version message?
if (Clang.getFrontendOpts().ShowVersion) {
if (Clang->getFrontendOpts().ShowVersion) {
llvm::cl::PrintVersionMessage();
return 0;
}
// Create the actual diagnostics engine.
Clang.createDiagnostics(ArgEnd - ArgBegin, const_cast<char**>(ArgBegin));
if (!Clang.hasDiagnostics())
Clang->createDiagnostics(ArgEnd - ArgBegin, const_cast<char**>(ArgBegin));
if (!Clang->hasDiagnostics())
return 1;
// Set an error handler, so that any LLVM backend diagnostics go through our
// error handler.
llvm::llvm_install_error_handler(LLVMErrorHandler,
static_cast<void*>(&Clang.getDiagnostics()));
static_cast<void*>(&Clang->getDiagnostics()));
DiagsBuffer.FlushDiagnostics(Clang.getDiagnostics());
DiagsBuffer.FlushDiagnostics(Clang->getDiagnostics());
// Load any requested plugins.
for (unsigned i = 0,
e = Clang.getFrontendOpts().Plugins.size(); i != e; ++i) {
const std::string &Path = Clang.getFrontendOpts().Plugins[i];
e = Clang->getFrontendOpts().Plugins.size(); i != e; ++i) {
const std::string &Path = Clang->getFrontendOpts().Plugins[i];
std::string Error;
if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(Path.c_str(), &Error))
Diags.Report(diag::err_fe_unable_to_load_plugin) << Path << Error;
@ -262,11 +262,20 @@ int cc1_main(const char **ArgBegin, const char **ArgEnd,
// If there were errors in processing arguments, don't do anything else.
bool Success = false;
if (!Clang.getDiagnostics().getNumErrors()) {
if (!Clang->getDiagnostics().getNumErrors()) {
// Create and execute the frontend action.
llvm::OwningPtr<FrontendAction> Act(CreateFrontendAction(Clang));
if (Act)
Success = Clang.ExecuteAction(*Act);
llvm::OwningPtr<FrontendAction> Act(CreateFrontendAction(*Clang));
if (Act) {
Success = Clang->ExecuteAction(*Act);
if (Clang->getFrontendOpts().DisableFree)
Act.take();
}
}
// When running with -disable-free, don't do any destruction or shutdown.
if (Clang->getFrontendOpts().DisableFree) {
Clang.take();
return !Success;
}
// Managed static deconstruction. Useful for making things like