[llvm] e793eee - [ORC] Add LLLazyJIT destructor with call to endSession. (#209399)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 14 03:18:45 PDT 2026


Author: Lang Hames
Date: 2026-07-14T20:18:40+10:00
New Revision: e793eee71340131b7dcbfd5fce2edde84ab4ad5a

URL: https://github.com/llvm/llvm-project/commit/e793eee71340131b7dcbfd5fce2edde84ab4ad5a
DIFF: https://github.com/llvm/llvm-project/commit/e793eee71340131b7dcbfd5fce2edde84ab4ad5a.diff

LOG: [ORC] Add LLLazyJIT destructor with call to endSession. (#209399)

Add an LLLazyJIT destructor with a call to ExecutionSession::endSession.
This ensures that the ExecutionSession's TaskDispatcher is shut down
(and in-flight tasks completed) before LLLazyJIT class members are
destroyed. Failure to do this could lead to use-after-free errors when
using thread-based task dispatch. This was likely the cause of flakiness
in test/ExecutionEngine/OrcLazy/multiple-compile-threads-basic.ll.

rdar://181982834

Added: 
    

Modified: 
    llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
    llvm/lib/ExecutionEngine/Orc/LLJIT.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h b/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
index 3ba472305066d..62fe44d6bcba7 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
@@ -296,6 +296,8 @@ class LLLazyJIT : public LLJIT {
     IPLayer->setPartitionFunction(std::move(Partition));
   }
 
+  LLVM_ABI ~LLLazyJIT();
+
   /// Returns a reference to the on-demand layer.
   CompileOnDemandLayer &getCompileOnDemandLayer() { return *CODLayer; }
 

diff  --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
index 18db7d24a8262..21e2c5ed41a83 100644
--- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
@@ -1312,6 +1312,14 @@ Error LLLazyJIT::addLazyIRModule(JITDylib &JD, ThreadSafeModule TSM) {
   return CODLayer->add(JD, std::move(TSM));
 }
 
+// End the session before this class's members (CODLayer, IPLayer, LCTMgr) are
+// destroyed: endSession joins the compile threads, and those threads may still
+// be operating on the CompileOnDemandLayer's per-dylib IndirectStubsManagers.
+LLLazyJIT::~LLLazyJIT() {
+  if (auto Err = ES->endSession())
+    ES->reportError(std::move(Err));
+}
+
 LLLazyJIT::LLLazyJIT(LLLazyJITBuilderState &S, Error &Err) : LLJIT(S, Err) {
 
   // If LLJIT construction failed then bail out.


        


More information about the llvm-commits mailing list