llvm.org GIT mirror llvm / fdf52d3
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256345 91177308-0d34-0410-b5e6-96231b3b80d8 Keno Fischer 3 years ago
2 changed file(s) with 34 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
941941 }
942942
943943 void Function::setPersonalityFn(Constant *Fn) {
944 if (Fn)
945 setHungoffOperand<0>(Fn);
944 setHungoffOperand<0>(Fn);
946945 setValueSubclassDataBit(3, Fn != nullptr);
947946 }
948947
952951 }
953952
954953 void Function::setPrefixData(Constant *PrefixData) {
955 if (PrefixData)
956 setHungoffOperand<1>(PrefixData);
954 setHungoffOperand<1>(PrefixData);
957955 setValueSubclassDataBit(1, PrefixData != nullptr);
958956 }
959957
963961 }
964962
965963 void Function::setPrologueData(Constant *PrologueData) {
966 if (PrologueData)
967 setHungoffOperand<2>(PrologueData);
964 setHungoffOperand<2>(PrologueData);
968965 setValueSubclassDataBit(2, PrologueData != nullptr);
969966 }
970967
985982
986983 template
987984 void Function::setHungoffOperand(Constant *C) {
988 assert(C && "Cannot set hungoff operand to nullptr");
989 allocHungoffUselist();
990 Op().set(C);
985 if (C) {
986 allocHungoffUselist();
987 Op().set(C);
988 } else if (getNumOperands()) {
989 Op().set(
990 ConstantPointerNull::get(Type::getInt1PtrTy(getContext(), 0)));
991 }
991992 }
992993
993994 void Function::setValueSubclassDataBit(unsigned Bit, bool On) {
9292 EXPECT_EQ(P.value_op_end(), (I - 2) + 8);
9393 }
9494
95 TEST(UserTest, PersonalityUser) {
96 Module M("", getGlobalContext());
97 FunctionType *RetVoidTy =
98 FunctionType::get(Type::getVoidTy(getGlobalContext()), false);
99 Function *PersonalityF = Function::Create(
100 RetVoidTy, GlobalValue::ExternalLinkage, "PersonalityFn", &M);
101 Function *TestF =
102 Function::Create(RetVoidTy, GlobalValue::ExternalLinkage, "TestFn", &M);
103
104 // Set up the personality function
105 TestF->setPersonalityFn(PersonalityF);
106 auto PersonalityUsers = PersonalityF->user_begin();
107
108 // One user and that user is the Test function
109 EXPECT_EQ(*PersonalityUsers, TestF);
110 EXPECT_EQ(++PersonalityUsers, PersonalityF->user_end());
111
112 // Reset the personality function
113 TestF->setPersonalityFn(nullptr);
114
115 // No users should remain
116 EXPECT_TRUE(TestF->user_empty());
117 }
118
95119 } // end anonymous namespace