[llvm] r256345 - [Function] Properly remove use when clearing personality

Keno Fischer via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 23 10:27:23 PST 2015


Author: kfischer
Date: Wed Dec 23 12:27:23 2015
New Revision: 256345

URL: http://llvm.org/viewvc/llvm-project?rev=256345&view=rev
Log:
[Function] Properly remove use when clearing personality

Summary:
We need to actually remove the use of the personality function,
otherwise we can run into trouble if we want to e.g. delete
the personality function because ther's no way to get rid of
its uses. Do this by resetting to ConstantPointerNull value
that the operands are set to when first allocated.

Reviewers: vsk, dexonsmith

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D15752

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

Modified: llvm/trunk/lib/IR/Function.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Function.cpp?rev=256345&r1=256344&r2=256345&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Function.cpp (original)
+++ llvm/trunk/lib/IR/Function.cpp Wed Dec 23 12:27:23 2015
@@ -942,8 +942,7 @@ Constant *Function::getPersonalityFn() c
 }
 
 void Function::setPersonalityFn(Constant *Fn) {
-  if (Fn)
-    setHungoffOperand<0>(Fn);
+  setHungoffOperand<0>(Fn);
   setValueSubclassDataBit(3, Fn != nullptr);
 }
 
@@ -953,8 +952,7 @@ Constant *Function::getPrefixData() cons
 }
 
 void Function::setPrefixData(Constant *PrefixData) {
-  if (PrefixData)
-    setHungoffOperand<1>(PrefixData);
+  setHungoffOperand<1>(PrefixData);
   setValueSubclassDataBit(1, PrefixData != nullptr);
 }
 
@@ -964,8 +962,7 @@ Constant *Function::getPrologueData() co
 }
 
 void Function::setPrologueData(Constant *PrologueData) {
-  if (PrologueData)
-    setHungoffOperand<2>(PrologueData);
+  setHungoffOperand<2>(PrologueData);
   setValueSubclassDataBit(2, PrologueData != nullptr);
 }
 
@@ -986,9 +983,13 @@ void Function::allocHungoffUselist() {
 
 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) {

Modified: llvm/trunk/unittests/IR/UserTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/UserTest.cpp?rev=256345&r1=256344&r2=256345&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/UserTest.cpp (original)
+++ llvm/trunk/unittests/IR/UserTest.cpp Wed Dec 23 12:27:23 2015
@@ -93,4 +93,28 @@ TEST(UserTest, ValueOpIteration) {
   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




More information about the llvm-commits mailing list