[llvm] [SPIR-V]: Memory leak fix in SPIRVEmitIntrinsics (PR #83015)

Michal Paszkowski via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 26 14:07:20 PST 2024


================
@@ -660,33 +669,34 @@ bool SPIRVEmitIntrinsics::runOnFunction(Function &Func) {
       AggrStores.insert(&I);
   }
 
-  IRB->SetInsertPoint(&Func.getEntryBlock(), Func.getEntryBlock().begin());
+  B.SetInsertPoint(&Func.getEntryBlock(), Func.getEntryBlock().begin());
   for (auto &GV : Func.getParent()->globals())
-    processGlobalValue(GV);
+    processGlobalValue(GV, B);
 
-  preprocessUndefs();
-  preprocessCompositeConstants();
+  preprocessUndefs(B);
+  preprocessCompositeConstants(B);
   SmallVector<Instruction *> Worklist;
   for (auto &I : instructions(Func))
     Worklist.push_back(&I);
 
   for (auto &I : Worklist) {
-    insertAssignPtrTypeIntrs(I);
-    insertAssignTypeIntrs(I);
-    insertPtrCastInstr(I);
+    insertAssignPtrTypeIntrs(I, B);
+    insertAssignTypeIntrs(I, B);
+    insertPtrCastInstr(I, B);
   }
-
+  this->IRB = &B;
----------------
michalpaszkowski wrote:

Thank you for the patch and catching the issue! Indeed, looks like we were not freeing IRB. However, I am wondering, would it be possible to either use only the B as the reference by passing it to pass' other methods or assign this->IRB early on in the runOnFunction and only use this approach. I think only the latter approach will be possible. 

Right now the methods we override rely on the IRB pointer, while the not overriding methods have B passed as a reference. Do you think it would be better to stick to just one approach?

https://github.com/llvm/llvm-project/pull/83015


More information about the llvm-commits mailing list