[PATCH] D15752: [Function] Properly remove use when clearing personality

Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 23 10:30:42 PST 2015


This revision was automatically updated to reflect the committed changes.
Closed by commit rL256345: [Function] Properly remove use when clearing personality (authored by kfischer).

Changed prior to commit:
  http://reviews.llvm.org/D15752?vs=43545&id=43548#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D15752

Files:
  llvm/trunk/lib/IR/Function.cpp
  llvm/trunk/unittests/IR/UserTest.cpp

Index: llvm/trunk/lib/IR/Function.cpp
===================================================================
--- llvm/trunk/lib/IR/Function.cpp
+++ llvm/trunk/lib/IR/Function.cpp
@@ -942,8 +942,7 @@
 }
 
 void Function::setPersonalityFn(Constant *Fn) {
-  if (Fn)
-    setHungoffOperand<0>(Fn);
+  setHungoffOperand<0>(Fn);
   setValueSubclassDataBit(3, Fn != nullptr);
 }
 
@@ -953,8 +952,7 @@
 }
 
 void Function::setPrefixData(Constant *PrefixData) {
-  if (PrefixData)
-    setHungoffOperand<1>(PrefixData);
+  setHungoffOperand<1>(PrefixData);
   setValueSubclassDataBit(1, PrefixData != nullptr);
 }
 
@@ -964,8 +962,7 @@
 }
 
 void Function::setPrologueData(Constant *PrologueData) {
-  if (PrologueData)
-    setHungoffOperand<2>(PrologueData);
+  setHungoffOperand<2>(PrologueData);
   setValueSubclassDataBit(2, PrologueData != nullptr);
 }
 
@@ -986,9 +983,13 @@
 
 template <int Idx>
 void Function::setHungoffOperand(Constant *C) {
-  assert(C && "Cannot set hungoff operand to nullptr");
-  allocHungoffUselist();
-  Op<Idx>().set(C);
+  if (C) {
+    allocHungoffUselist();
+    Op<Idx>().set(C);
+  } else if (getNumOperands()) {
+    Op<Idx>().set(
+        ConstantPointerNull::get(Type::getInt1PtrTy(getContext(), 0)));
+  }
 }
 
 void Function::setValueSubclassDataBit(unsigned Bit, bool On) {
Index: llvm/trunk/unittests/IR/UserTest.cpp
===================================================================
--- llvm/trunk/unittests/IR/UserTest.cpp
+++ llvm/trunk/unittests/IR/UserTest.cpp
@@ -93,4 +93,28 @@
   EXPECT_EQ(P.value_op_end(), (I - 2) + 8);
 }
 
+TEST(UserTest, PersonalityUser) {
+  Module M("", getGlobalContext());
+  FunctionType *RetVoidTy =
+      FunctionType::get(Type::getVoidTy(getGlobalContext()), false);
+  Function *PersonalityF = Function::Create(
+      RetVoidTy, GlobalValue::ExternalLinkage, "PersonalityFn", &M);
+  Function *TestF =
+      Function::Create(RetVoidTy, GlobalValue::ExternalLinkage, "TestFn", &M);
+
+  // Set up the personality function
+  TestF->setPersonalityFn(PersonalityF);
+  auto PersonalityUsers = PersonalityF->user_begin();
+
+  // One user and that user is the Test function
+  EXPECT_EQ(*PersonalityUsers, TestF);
+  EXPECT_EQ(++PersonalityUsers, PersonalityF->user_end());
+
+  // Reset the personality function
+  TestF->setPersonalityFn(nullptr);
+
+  // No users should remain
+  EXPECT_TRUE(TestF->user_empty());
+}
+
 } // end anonymous namespace


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15752.43548.patch
Type: text/x-patch
Size: 2430 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151223/b0560457/attachment.bin>


More information about the llvm-commits mailing list