Index: clang/include/clang/Interpreter/Interpreter.h =================================================================== --- clang/include/clang/Interpreter/Interpreter.h +++ clang/include/clang/Interpreter/Interpreter.h @@ -68,6 +68,7 @@ return Execute(*PTU); return llvm::Error::success(); } + llvm::Error CleanUp(); /// \returns the \c JITTargetAddress of a \c GlobalDecl. This interface uses /// the CodeGenModule's internal mangling cache to avoid recomputing the 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 @@ -182,6 +182,12 @@ Interpreter::~Interpreter() {} +llvm::Error Interpreter::CleanUp() { + if (IncrExecutor) + return IncrExecutor->cleanUp(); + return llvm::Error::success(); +} + llvm::Expected> Interpreter::create(std::unique_ptr CI) { llvm::Error Err = llvm::Error::success(); Index: clang/tools/clang-repl/ClangRepl.cpp =================================================================== --- clang/tools/clang-repl/ClangRepl.cpp +++ clang/tools/clang-repl/ClangRepl.cpp @@ -99,6 +99,8 @@ } } + ExitOnErr(Interp->CleanUp()); + // Our error handler depends on the Diagnostics object, which we're // potentially about to delete. Uninstall the handler now so that any // later errors use the default handling behavior instead.