}
void Function::setPersonalityFn(Constant *Fn) {
- if (Fn)
- setHungoffOperand<0>(Fn);
+ setHungoffOperand<0>(Fn);
setValueSubclassDataBit(3, Fn != nullptr);
}
}
void Function::setPrefixData(Constant *PrefixData) {
- if (PrefixData)
- setHungoffOperand<1>(PrefixData);
+ setHungoffOperand<1>(PrefixData);
setValueSubclassDataBit(1, PrefixData != nullptr);
}
}
void Function::setPrologueData(Constant *PrologueData) {
- if (PrologueData)
- setHungoffOperand<2>(PrologueData);
+ setHungoffOperand<2>(PrologueData);
setValueSubclassDataBit(2, PrologueData != nullptr);
}
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) {
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