diff options
-rw-r--r-- | llvm/include/llvm/LTO/LTOCodeGenerator.h | 2 | ||||
-rw-r--r-- | llvm/tools/lto/lto.cpp | 4 |
2 files changed, 6 insertions, 0 deletions
diff --git a/llvm/include/llvm/LTO/LTOCodeGenerator.h b/llvm/include/llvm/LTO/LTOCodeGenerator.h index 876defbdcd3..8a79e6044f5 100644 --- a/llvm/include/llvm/LTO/LTOCodeGenerator.h +++ b/llvm/include/llvm/LTO/LTOCodeGenerator.h @@ -148,6 +148,8 @@ struct LTOCodeGenerator { LLVMContext &getContext() { return Context; } + void resetMergedModule() { MergedModule.reset(); } + private: void initializeLTOPasses(); diff --git a/llvm/tools/lto/lto.cpp b/llvm/tools/lto/lto.cpp index d13de57e830..d8f99c050a3 100644 --- a/llvm/tools/lto/lto.cpp +++ b/llvm/tools/lto/lto.cpp @@ -124,6 +124,10 @@ struct LibLTOCodeGenerator : LTOCodeGenerator { : LTOCodeGenerator(*Context), OwnedContext(std::move(Context)) { setDiagnosticHandler(handleLibLTODiagnostic, nullptr); } + // Reset the module first in case MergedModule is created in OwnedContext. + // Module must be destructed before its context gets destructed. + ~LibLTOCodeGenerator() { resetMergedModule(); } + std::unique_ptr<MemoryBuffer> NativeObjectFile; std::unique_ptr<LLVMContext> OwnedContext; }; |