Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit fdf52d3

Browse files
committed
[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
1 parent d7f93b3 commit fdf52d3

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

lib/IR/Function.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -942,8 +942,7 @@ Constant *Function::getPersonalityFn() const {
942942
}
943943

944944
void Function::setPersonalityFn(Constant *Fn) {
945-
if (Fn)
946-
setHungoffOperand<0>(Fn);
945+
setHungoffOperand<0>(Fn);
947946
setValueSubclassDataBit(3, Fn != nullptr);
948947
}
949948

@@ -953,8 +952,7 @@ Constant *Function::getPrefixData() const {
953952
}
954953

955954
void Function::setPrefixData(Constant *PrefixData) {
956-
if (PrefixData)
957-
setHungoffOperand<1>(PrefixData);
955+
setHungoffOperand<1>(PrefixData);
958956
setValueSubclassDataBit(1, PrefixData != nullptr);
959957
}
960958

@@ -964,8 +962,7 @@ Constant *Function::getPrologueData() const {
964962
}
965963

966964
void Function::setPrologueData(Constant *PrologueData) {
967-
if (PrologueData)
968-
setHungoffOperand<2>(PrologueData);
965+
setHungoffOperand<2>(PrologueData);
969966
setValueSubclassDataBit(2, PrologueData != nullptr);
970967
}
971968

@@ -986,9 +983,13 @@ void Function::allocHungoffUselist() {
986983

987984
template <int Idx>
988985
void Function::setHungoffOperand(Constant *C) {
989-
assert(C && "Cannot set hungoff operand to nullptr");
990-
allocHungoffUselist();
991-
Op<Idx>().set(C);
986+
if (C) {
987+
allocHungoffUselist();
988+
Op<Idx>().set(C);
989+
} else if (getNumOperands()) {
990+
Op<Idx>().set(
991+
ConstantPointerNull::get(Type::getInt1PtrTy(getContext(), 0)));
992+
}
992993
}
993994

994995
void Function::setValueSubclassDataBit(unsigned Bit, bool On) {

unittests/IR/UserTest.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,28 @@ TEST(UserTest, ValueOpIteration) {
9393
EXPECT_EQ(P.value_op_end(), (I - 2) + 8);
9494
}
9595

96+
TEST(UserTest, PersonalityUser) {
97+
Module M("", getGlobalContext());
98+
FunctionType *RetVoidTy =
99+
FunctionType::get(Type::getVoidTy(getGlobalContext()), false);
100+
Function *PersonalityF = Function::Create(
101+
RetVoidTy, GlobalValue::ExternalLinkage, "PersonalityFn", &M);
102+
Function *TestF =
103+
Function::Create(RetVoidTy, GlobalValue::ExternalLinkage, "TestFn", &M);
104+
105+
// Set up the personality function
106+
TestF->setPersonalityFn(PersonalityF);
107+
auto PersonalityUsers = PersonalityF->user_begin();
108+
109+
// One user and that user is the Test function
110+
EXPECT_EQ(*PersonalityUsers, TestF);
111+
EXPECT_EQ(++PersonalityUsers, PersonalityF->user_end());
112+
113+
// Reset the personality function
114+
TestF->setPersonalityFn(nullptr);
115+
116+
// No users should remain
117+
EXPECT_TRUE(TestF->user_empty());
118+
}
119+
96120
} // end anonymous namespace

0 commit comments

Comments
 (0)