Index: clang/lib/Interpreter/IncrementalExecutor.h =================================================================== --- clang/lib/Interpreter/IncrementalExecutor.h +++ clang/lib/Interpreter/IncrementalExecutor.h @@ -43,6 +43,7 @@ llvm::Error addModule(std::unique_ptr M); llvm::Error runCtors() const; + llvm::Error cleanUp(); llvm::Expected getSymbolAddress(llvm::StringRef Name, SymbolNameKind NameKind) const; llvm::orc::LLJIT *getExecutionEngine() const { return Jit.get(); } Index: clang/lib/Interpreter/IncrementalExecutor.cpp =================================================================== --- clang/lib/Interpreter/IncrementalExecutor.cpp +++ clang/lib/Interpreter/IncrementalExecutor.cpp @@ -52,6 +52,10 @@ IncrementalExecutor::~IncrementalExecutor() {} +llvm::Error IncrementalExecutor::cleanUp() { + return Jit->deinitialize(Jit->getMainJITDylib()); +} + llvm::Error IncrementalExecutor::addModule(std::unique_ptr M) { return Jit->addIRModule(llvm::orc::ThreadSafeModule(std::move(M), TSCtx)); } Index: clang/lib/Interpreter/Interpreter.cpp =================================================================== --- clang/lib/Interpreter/Interpreter.cpp +++ clang/lib/Interpreter/Interpreter.cpp @@ -183,7 +183,14 @@ *TSCtx->getContext(), Err); } -Interpreter::~Interpreter() {} +Interpreter::~Interpreter() { + if (IncrExecutor) { + if (llvm::Error Err = IncrExecutor->cleanUp()) + llvm::report_fatal_error( + llvm::Twine("Failed to clean up IncrementalExecutor: ") + + toString(std::move(Err))); + } +} llvm::Expected> Interpreter::create(std::unique_ptr CI) { Index: clang/test/Interpreter/execute.cpp =================================================================== --- clang/test/Interpreter/execute.cpp +++ clang/test/Interpreter/execute.cpp @@ -1,3 +1,4 @@ +// clang-format off // RUN: clang-repl "int x = 10;" "int y=7; err;" "int y = 10;" // RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \ // RUN: 'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s @@ -18,4 +19,7 @@ inline int foo() { return 42; } int r3 = foo(); +struct D { float f = 1.0; D *m = nullptr; D(){} ~D() { printf("D[f=%f, m=0x%llx]\n", f, reinterpret_cast(m)); }} d; +// CHECK: D[f=1.000000, m=0x0] + quit Index: clang/tools/clang-repl/ClangRepl.cpp =================================================================== --- clang/tools/clang-repl/ClangRepl.cpp +++ clang/tools/clang-repl/ClangRepl.cpp @@ -70,6 +70,8 @@ ExitOnErr.setBanner("clang-repl: "); llvm::cl::ParseCommandLineOptions(argc, argv); + llvm::llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. + std::vector ClangArgv(ClangArgs.size()); std::transform(ClangArgs.begin(), ClangArgs.end(), ClangArgv.begin(), [](const std::string &s) -> const char * { return s.data(); }); @@ -121,7 +123,5 @@ // later errors use the default handling behavior instead. llvm::remove_fatal_error_handler(); - llvm::llvm_shutdown(); - return checkDiagErrors(Interp->getCompilerInstance()); }