[PATCH] D119064: [orc] Change LLJIT's dtor to a virtual dtor

Sameer Rahmani via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 5 15:01:52 PST 2022


lxsameer created this revision.
lxsameer added a reviewer: lhames.
lxsameer requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Since `LLLazyJIT` inherits from `LLJIT`, the following is valid:

      
  class A {
    std::unique_ptr<LLJIT> jit;
  };
      
  auto lazyJit = createLLLazyJIT(..);
  A example(lazyJit);
      

But whet `jit` gets destroyed only the dtor of `LLJIT` will be called and
it will cause memory leaks on the members of `LLLazyJIT`.

      

With a virtual dtor for `LLJIT`, `LLLazyJIT` dtor will be called first.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119064

Files:
  llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h


Index: llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
===================================================================
--- llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
+++ llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
@@ -56,7 +56,7 @@
 
   /// Destruct this instance. If a multi-threaded instance, waits for all
   /// compile threads to complete.
-  ~LLJIT();
+  virtual ~LLJIT();
 
   /// Returns the ExecutionSession for this instance.
   ExecutionSession &getExecutionSession() { return *ES; }
@@ -221,10 +221,8 @@
   template <typename, typename, typename> friend class LLJITBuilderSetters;
 
 public:
-
   /// Sets the partition function.
-  void
-  setPartitionFunction(CompileOnDemandLayer::PartitionFunction Partition) {
+  void setPartitionFunction(CompileOnDemandLayer::PartitionFunction Partition) {
     CODLayer->setPartitionFunction(std::move(Partition));
   }
 
@@ -240,7 +238,6 @@
   }
 
 private:
-
   // Create a single-threaded LLLazyJIT instance.
   LLLazyJIT(LLLazyJITBuilderState &S, Error &Err);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119064.406214.patch
Type: text/x-patch
Size: 1026 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220205/db800d20/attachment.bin>


More information about the llvm-commits mailing list