[llvm] 3e15bce - [FuzzMutate] replace undef placeholders with poison
Nuno Lopes via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 20 06:11:23 PST 2024
Author: Nuno Lopes
Date: 2024-11-20T14:09:39Z
New Revision: 3e15bce9e1e144c0e568eed10010fa0e359e8ec2
URL: https://github.com/llvm/llvm-project/commit/3e15bce9e1e144c0e568eed10010fa0e359e8ec2
DIFF: https://github.com/llvm/llvm-project/commit/3e15bce9e1e144c0e568eed10010fa0e359e8ec2.diff
LOG: [FuzzMutate] replace undef placeholders with poison
Added:
Modified:
llvm/include/llvm/FuzzMutate/OpDescriptor.h
llvm/lib/FuzzMutate/Operations.cpp
llvm/lib/FuzzMutate/RandomIRBuilder.cpp
llvm/unittests/FuzzMutate/OperationsTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/FuzzMutate/OpDescriptor.h b/llvm/include/llvm/FuzzMutate/OpDescriptor.h
index 78114074dbbfce..4a3c2f767d00c8 100644
--- a/llvm/include/llvm/FuzzMutate/OpDescriptor.h
+++ b/llvm/include/llvm/FuzzMutate/OpDescriptor.h
@@ -63,7 +63,7 @@ class SourcePred {
// 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;
};
diff --git a/llvm/lib/FuzzMutate/Operations.cpp b/llvm/lib/FuzzMutate/Operations.cpp
index 389ff8130771c8..c9cad7d142760c 100644
--- a/llvm/lib/FuzzMutate/Operations.cpp
+++ b/llvm/lib/FuzzMutate/Operations.cpp
@@ -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};
}
diff --git a/llvm/lib/FuzzMutate/RandomIRBuilder.cpp b/llvm/lib/FuzzMutate/RandomIRBuilder.cpp
index b645888463b12a..a684307586a61d 100644
--- a/llvm/lib/FuzzMutate/RandomIRBuilder.cpp
+++ b/llvm/lib/FuzzMutate/RandomIRBuilder.cpp
@@ -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));
}
}
diff --git a/llvm/unittests/FuzzMutate/OperationsTest.cpp b/llvm/unittests/FuzzMutate/OperationsTest.cpp
index bc972ad21d049f..b4a7bb70f328f9 100644
--- a/llvm/unittests/FuzzMutate/OperationsTest.cpp
+++ b/llvm/unittests/FuzzMutate/OperationsTest.cpp
@@ -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}, {}),
More information about the llvm-commits
mailing list