[PATCH] D156618: [IR] Fix a memory leak if Function::dropAllReferences() is followed by setHungoffOperand

Duncan P. N. Exon Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 14 08:54:57 PDT 2023


dexonsmith added inline comments.


================
Comment at: llvm/include/llvm/IR/Function.h:119
 
+  void deleteBodyImpl();
+
----------------
I think you should add a parameter `bool ShouldDrop` so that you can share logic between `dropAllReferences()` and `deleteBody()`.


================
Comment at: llvm/include/llvm/IR/Function.h:672
   void deleteBody() {
-    dropAllReferences();
+    deleteBodyImpl();
     setLinkage(ExternalLinkage);
----------------
This can be `deleteBodyImpl(/*ShouldDrop*/=false)`.


================
Comment at: llvm/lib/IR/Function.cpp:529
 //
 void Function::dropAllReferences() {
   setIsMaterializable(false);
----------------
This can move to the header and just call `deleteBlodyImpl(/*ShouldDrop=*/true)`.


================
Comment at: llvm/lib/IR/Function.cpp:566-570
+    auto *CPN = ConstantPointerNull::get(PointerType::get(getContext(), 0));
+    Op<0>().set(CPN);
+    Op<1>().set(CPN);
+    Op<2>().set(CPN);
+    setValueSubclassData(getSubclassDataFromValue() & ~0xe);
----------------
This behaviour can depend on `ShouldDrop`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156618/new/

https://reviews.llvm.org/D156618



More information about the llvm-commits mailing list