[FuzzMutate] replace undef placeholders with poison

This commit is contained in:
Nuno Lopes
2024-11-20 14:09:39 +00:00
parent 71b87d1267
commit 3e15bce9e1
4 changed files with 23 additions and 23 deletions

View File

@@ -63,7 +63,7 @@ public:
// Default filter just calls Pred on each of the base types.
std::vector<Constant *> Result;
for (Type *T : BaseTypes) {
Constant *V = UndefValue::get(T);
Constant *V = PoisonValue::get(T);
if (Pred(Cur, V))
makeConstantsWithType(T, Result);
}
@@ -155,7 +155,7 @@ static inline SourcePred anyPtrType() {
std::vector<Constant *> Result;
// TODO: Should these point at something?
for (Type *T : Ts)
Result.push_back(UndefValue::get(PointerType::getUnqual(T)));
Result.push_back(PoisonValue::get(PointerType::getUnqual(T)));
return Result;
};
return {Pred, Make};
@@ -175,7 +175,7 @@ static inline SourcePred sizedPtrType() {
// as the pointer type will always be the same.
for (Type *T : Ts)
if (T->isSized())
Result.push_back(UndefValue::get(PointerType::getUnqual(T)));
Result.push_back(PoisonValue::get(PointerType::getUnqual(T)));
return Result;
};

View File

@@ -182,9 +182,9 @@ OpDescriptor llvm::fuzzerop::splitBlockDescriptor(unsigned Weight) {
// We need values for each phi in the block. Since there isn't a good way
// to do a variable number of input values currently, we just fill them
// with undef.
// with poison.
for (PHINode &PHI : Block->phis())
PHI.addIncoming(UndefValue::get(PHI.getType()), Block);
PHI.addIncoming(PoisonValue::get(PHI.getType()), Block);
}
return nullptr;
};
@@ -342,7 +342,7 @@ static SourcePred validShuffleVectorIndex() {
// TODO: It's straighforward to make up reasonable values, but listing them
// exhaustively would be insane. Come up with a couple of sensible ones.
return std::vector<Constant *>{
UndefValue::get(VectorType::get(Int32Ty, FirstTy->getElementCount()))};
PoisonValue::get(VectorType::get(Int32Ty, FirstTy->getElementCount()))};
};
return {Pred, Make};
}

View File

@@ -81,7 +81,7 @@ RandomIRBuilder::findOrCreateGlobalVariable(Module *M, ArrayRef<Value *> Srcs,
auto MatchesPred = [&Srcs, &Pred](GlobalVariable *GV) {
// Can't directly compare GV's type, as it would be a pointer to the actual
// type.
return Pred.matches(Srcs, UndefValue::get(GV->getValueType()));
return Pred.matches(Srcs, PoisonValue::get(GV->getValueType()));
};
bool DidCreate = false;
SmallVector<GlobalVariable *, 4> GlobalVars;
@@ -368,9 +368,9 @@ Instruction *RandomIRBuilder::newSink(BasicBlock &BB,
if (!Ptr) {
if (uniform(Rand, 0, 1)) {
Type *Ty = V->getType();
Ptr = createStackMemory(BB.getParent(), Ty, UndefValue::get(Ty));
Ptr = createStackMemory(BB.getParent(), Ty, PoisonValue::get(Ty));
} else {
Ptr = UndefValue::get(PointerType::get(V->getType(), 0));
Ptr = PoisonValue::get(PointerType::get(V->getType(), 0));
}
}

View File

@@ -261,7 +261,7 @@ TEST(OperationsTest, SplitBlock) {
// Create a block with only a return and split it on the return.
auto *BB = BasicBlock::Create(Ctx, "BB", F);
auto *RI = ReturnInst::Create(Ctx, BB);
SBOp.BuilderFunc({UndefValue::get(Type::getInt1Ty(Ctx))}, RI->getIterator());
SBOp.BuilderFunc({PoisonValue::get(Type::getInt1Ty(Ctx))}, RI->getIterator());
// We should end up with an unconditional branch from BB to BB1, and the
// return ends up in BB1.
@@ -368,11 +368,11 @@ TEST(OperationsTest, GEP) {
auto *RI = ReturnInst::Create(Ctx, BB);
auto GEPOp = fuzzerop::gepDescriptor(1);
EXPECT_TRUE(GEPOp.SourcePreds[0].matches({}, UndefValue::get(Int8PtrTy)));
EXPECT_TRUE(GEPOp.SourcePreds[1].matches({UndefValue::get(Int8PtrTy)},
EXPECT_TRUE(GEPOp.SourcePreds[0].matches({}, PoisonValue::get(Int8PtrTy)));
EXPECT_TRUE(GEPOp.SourcePreds[1].matches({PoisonValue::get(Int8PtrTy)},
ConstantInt::get(Int32Ty, 0)));
GEPOp.BuilderFunc({UndefValue::get(Int8PtrTy), ConstantInt::get(Int32Ty, 0)},
GEPOp.BuilderFunc({PoisonValue::get(Int8PtrTy), ConstantInt::get(Int32Ty, 0)},
RI->getIterator());
EXPECT_FALSE(verifyModule(M, &errs()));
}
@@ -419,11 +419,11 @@ TEST(OperationsTest, ExtractAndInsertValue) {
auto IVOp = fuzzerop::insertValueDescriptor(1);
// Sanity check the source preds.
Constant *SVal = UndefValue::get(StructTy);
Constant *OVal = UndefValue::get(OpaqueTy);
Constant *AVal = UndefValue::get(ArrayTy);
Constant *ZAVal = UndefValue::get(ZeroSizedArrayTy);
Constant *VVal = UndefValue::get(VectorTy);
Constant *SVal = PoisonValue::get(StructTy);
Constant *OVal = PoisonValue::get(OpaqueTy);
Constant *AVal = PoisonValue::get(ArrayTy);
Constant *ZAVal = PoisonValue::get(ZeroSizedArrayTy);
Constant *VVal = PoisonValue::get(VectorTy);
EXPECT_TRUE(EVOp.SourcePreds[0].matches({}, SVal));
EXPECT_FALSE(EVOp.SourcePreds[0].matches({}, OVal));
@@ -462,12 +462,12 @@ TEST(OperationsTest, ExtractAndInsertValue) {
// InsertValue should accept any type in the struct, but only in positions
// where it makes sense.
EXPECT_TRUE(IVOp.SourcePreds[1].matches({SVal}, UndefValue::get(Int8PtrTy)));
EXPECT_TRUE(IVOp.SourcePreds[1].matches({SVal}, UndefValue::get(Int32Ty)));
EXPECT_FALSE(IVOp.SourcePreds[1].matches({SVal}, UndefValue::get(Int64Ty)));
EXPECT_FALSE(IVOp.SourcePreds[2].matches({SVal, UndefValue::get(Int32Ty)},
EXPECT_TRUE(IVOp.SourcePreds[1].matches({SVal}, PoisonValue::get(Int8PtrTy)));
EXPECT_TRUE(IVOp.SourcePreds[1].matches({SVal}, PoisonValue::get(Int32Ty)));
EXPECT_FALSE(IVOp.SourcePreds[1].matches({SVal}, PoisonValue::get(Int64Ty)));
EXPECT_FALSE(IVOp.SourcePreds[2].matches({SVal, PoisonValue::get(Int32Ty)},
ConstantInt::get(Int32Ty, 0)));
EXPECT_TRUE(IVOp.SourcePreds[2].matches({SVal, UndefValue::get(Int32Ty)},
EXPECT_TRUE(IVOp.SourcePreds[2].matches({SVal, PoisonValue::get(Int32Ty)},
ConstantInt::get(Int32Ty, 1)));
EXPECT_THAT(IVOp.SourcePreds[1].generate({SVal}, {}),