[PATCH] D15450: Avoid double deletion in Clang driver.
Serge Pavlov via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 18 08:46:45 PST 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL261222: Avoid double deletion in Clang driver. (authored by sepavloff).
Changed prior to commit:
http://reviews.llvm.org/D15450?vs=46575&id=48332#toc
Repository:
rL LLVM
http://reviews.llvm.org/D15450
Files:
cfe/trunk/lib/CodeGen/CodeGenAction.cpp
cfe/trunk/unittests/Frontend/CMakeLists.txt
Index: cfe/trunk/lib/CodeGen/CodeGenAction.cpp
===================================================================
--- cfe/trunk/lib/CodeGen/CodeGenAction.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenAction.cpp
@@ -53,7 +53,6 @@
std::unique_ptr<CodeGenerator> Gen;
- std::unique_ptr<llvm::Module> TheModule;
SmallVector<std::pair<unsigned, std::unique_ptr<llvm::Module>>, 4>
LinkModules;
@@ -81,7 +80,10 @@
this->LinkModules.push_back(
std::make_pair(I.first, std::unique_ptr<llvm::Module>(I.second)));
}
- std::unique_ptr<llvm::Module> takeModule() { return std::move(TheModule); }
+ llvm::Module *getModule() const { return Gen->GetModule(); }
+ std::unique_ptr<llvm::Module> takeModule() {
+ return std::unique_ptr<llvm::Module>(Gen->ReleaseModule());
+ }
void releaseLinkModules() {
for (auto &I : LinkModules)
I.second.release();
@@ -101,8 +103,6 @@
Gen->Initialize(Ctx);
- TheModule.reset(Gen->GetModule());
-
if (llvm::TimePassesIsEnabled)
LLVMIRGeneration.stopTimer();
}
@@ -149,25 +149,12 @@
}
// Silently ignore if we weren't initialized for some reason.
- if (!TheModule)
- return;
-
- // Make sure IR generation is happy with the module. This is released by
- // the module provider.
- llvm::Module *M = Gen->ReleaseModule();
- if (!M) {
- // The module has been released by IR gen on failures, do not double
- // free.
- TheModule.release();
+ if (!getModule())
return;
- }
-
- assert(TheModule.get() == M &&
- "Unexpected module change during IR generation");
// Install an inline asm handler so that diagnostics get printed through
// our diagnostics hooks.
- LLVMContext &Ctx = TheModule->getContext();
+ LLVMContext &Ctx = getModule()->getContext();
LLVMContext::InlineAsmDiagHandlerTy OldHandler =
Ctx.getInlineAsmDiagnosticHandler();
void *OldContext = Ctx.getInlineAsmDiagnosticContext();
@@ -182,13 +169,13 @@
for (auto &I : LinkModules) {
unsigned LinkFlags = I.first;
CurLinkModule = I.second.get();
- if (Linker::linkModules(*M, std::move(I.second), LinkFlags))
+ if (Linker::linkModules(*getModule(), std::move(I.second), LinkFlags))
return;
}
EmitBackendOutput(Diags, CodeGenOpts, TargetOpts, LangOpts,
C.getTargetInfo().getDataLayoutString(),
- TheModule.get(), Action, AsmOutStream);
+ getModule(), Action, AsmOutStream);
Ctx.setInlineAsmDiagnosticHandler(OldHandler, OldContext);
Index: cfe/trunk/unittests/Frontend/CMakeLists.txt
===================================================================
--- cfe/trunk/unittests/Frontend/CMakeLists.txt
+++ cfe/trunk/unittests/Frontend/CMakeLists.txt
@@ -4,11 +4,13 @@
add_clang_unittest(FrontendTests
FrontendActionTest.cpp
+ CodeGenActionTest.cpp
)
target_link_libraries(FrontendTests
clangAST
clangBasic
clangFrontend
clangLex
clangSema
+ clangCodeGen
)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15450.48332.patch
Type: text/x-patch
Size: 3184 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160218/2234fafd/attachment.bin>
More information about the cfe-commits
mailing list