Skip to content

Commit 3e15bce

Browse files
committed
[FuzzMutate] replace undef placeholders with poison
1 parent 71b87d1 commit 3e15bce

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

llvm/include/llvm/FuzzMutate/OpDescriptor.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class SourcePred {
6363
// Default filter just calls Pred on each of the base types.
6464
std::vector<Constant *> Result;
6565
for (Type *T : BaseTypes) {
66-
Constant *V = UndefValue::get(T);
66+
Constant *V = PoisonValue::get(T);
6767
if (Pred(Cur, V))
6868
makeConstantsWithType(T, Result);
6969
}
@@ -155,7 +155,7 @@ static inline SourcePred anyPtrType() {
155155
std::vector<Constant *> Result;
156156
// TODO: Should these point at something?
157157
for (Type *T : Ts)
158-
Result.push_back(UndefValue::get(PointerType::getUnqual(T)));
158+
Result.push_back(PoisonValue::get(PointerType::getUnqual(T)));
159159
return Result;
160160
};
161161
return {Pred, Make};
@@ -175,7 +175,7 @@ static inline SourcePred sizedPtrType() {
175175
// as the pointer type will always be the same.
176176
for (Type *T : Ts)
177177
if (T->isSized())
178-
Result.push_back(UndefValue::get(PointerType::getUnqual(T)));
178+
Result.push_back(PoisonValue::get(PointerType::getUnqual(T)));
179179

180180
return Result;
181181
};

llvm/lib/FuzzMutate/Operations.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ OpDescriptor llvm::fuzzerop::splitBlockDescriptor(unsigned Weight) {
182182

183183
// We need values for each phi in the block. Since there isn't a good way
184184
// to do a variable number of input values currently, we just fill them
185-
// with undef.
185+
// with poison.
186186
for (PHINode &PHI : Block->phis())
187-
PHI.addIncoming(UndefValue::get(PHI.getType()), Block);
187+
PHI.addIncoming(PoisonValue::get(PHI.getType()), Block);
188188
}
189189
return nullptr;
190190
};
@@ -342,7 +342,7 @@ static SourcePred validShuffleVectorIndex() {
342342
// TODO: It's straighforward to make up reasonable values, but listing them
343343
// exhaustively would be insane. Come up with a couple of sensible ones.
344344
return std::vector<Constant *>{
345-
UndefValue::get(VectorType::get(Int32Ty, FirstTy->getElementCount()))};
345+
PoisonValue::get(VectorType::get(Int32Ty, FirstTy->getElementCount()))};
346346
};
347347
return {Pred, Make};
348348
}

llvm/lib/FuzzMutate/RandomIRBuilder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ RandomIRBuilder::findOrCreateGlobalVariable(Module *M, ArrayRef<Value *> Srcs,
8181
auto MatchesPred = [&Srcs, &Pred](GlobalVariable *GV) {
8282
// Can't directly compare GV's type, as it would be a pointer to the actual
8383
// type.
84-
return Pred.matches(Srcs, UndefValue::get(GV->getValueType()));
84+
return Pred.matches(Srcs, PoisonValue::get(GV->getValueType()));
8585
};
8686
bool DidCreate = false;
8787
SmallVector<GlobalVariable *, 4> GlobalVars;
@@ -368,9 +368,9 @@ Instruction *RandomIRBuilder::newSink(BasicBlock &BB,
368368
if (!Ptr) {
369369
if (uniform(Rand, 0, 1)) {
370370
Type *Ty = V->getType();
371-
Ptr = createStackMemory(BB.getParent(), Ty, UndefValue::get(Ty));
371+
Ptr = createStackMemory(BB.getParent(), Ty, PoisonValue::get(Ty));
372372
} else {
373-
Ptr = UndefValue::get(PointerType::get(V->getType(), 0));
373+
Ptr = PoisonValue::get(PointerType::get(V->getType(), 0));
374374
}
375375
}
376376

llvm/unittests/FuzzMutate/OperationsTest.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ TEST(OperationsTest, SplitBlock) {
261261
// Create a block with only a return and split it on the return.
262262
auto *BB = BasicBlock::Create(Ctx, "BB", F);
263263
auto *RI = ReturnInst::Create(Ctx, BB);
264-
SBOp.BuilderFunc({UndefValue::get(Type::getInt1Ty(Ctx))}, RI->getIterator());
264+
SBOp.BuilderFunc({PoisonValue::get(Type::getInt1Ty(Ctx))}, RI->getIterator());
265265

266266
// We should end up with an unconditional branch from BB to BB1, and the
267267
// return ends up in BB1.
@@ -368,11 +368,11 @@ TEST(OperationsTest, GEP) {
368368
auto *RI = ReturnInst::Create(Ctx, BB);
369369

370370
auto GEPOp = fuzzerop::gepDescriptor(1);
371-
EXPECT_TRUE(GEPOp.SourcePreds[0].matches({}, UndefValue::get(Int8PtrTy)));
372-
EXPECT_TRUE(GEPOp.SourcePreds[1].matches({UndefValue::get(Int8PtrTy)},
371+
EXPECT_TRUE(GEPOp.SourcePreds[0].matches({}, PoisonValue::get(Int8PtrTy)));
372+
EXPECT_TRUE(GEPOp.SourcePreds[1].matches({PoisonValue::get(Int8PtrTy)},
373373
ConstantInt::get(Int32Ty, 0)));
374374

375-
GEPOp.BuilderFunc({UndefValue::get(Int8PtrTy), ConstantInt::get(Int32Ty, 0)},
375+
GEPOp.BuilderFunc({PoisonValue::get(Int8PtrTy), ConstantInt::get(Int32Ty, 0)},
376376
RI->getIterator());
377377
EXPECT_FALSE(verifyModule(M, &errs()));
378378
}
@@ -419,11 +419,11 @@ TEST(OperationsTest, ExtractAndInsertValue) {
419419
auto IVOp = fuzzerop::insertValueDescriptor(1);
420420

421421
// Sanity check the source preds.
422-
Constant *SVal = UndefValue::get(StructTy);
423-
Constant *OVal = UndefValue::get(OpaqueTy);
424-
Constant *AVal = UndefValue::get(ArrayTy);
425-
Constant *ZAVal = UndefValue::get(ZeroSizedArrayTy);
426-
Constant *VVal = UndefValue::get(VectorTy);
422+
Constant *SVal = PoisonValue::get(StructTy);
423+
Constant *OVal = PoisonValue::get(OpaqueTy);
424+
Constant *AVal = PoisonValue::get(ArrayTy);
425+
Constant *ZAVal = PoisonValue::get(ZeroSizedArrayTy);
426+
Constant *VVal = PoisonValue::get(VectorTy);
427427

428428
EXPECT_TRUE(EVOp.SourcePreds[0].matches({}, SVal));
429429
EXPECT_FALSE(EVOp.SourcePreds[0].matches({}, OVal));
@@ -462,12 +462,12 @@ TEST(OperationsTest, ExtractAndInsertValue) {
462462

463463
// InsertValue should accept any type in the struct, but only in positions
464464
// where it makes sense.
465-
EXPECT_TRUE(IVOp.SourcePreds[1].matches({SVal}, UndefValue::get(Int8PtrTy)));
466-
EXPECT_TRUE(IVOp.SourcePreds[1].matches({SVal}, UndefValue::get(Int32Ty)));
467-
EXPECT_FALSE(IVOp.SourcePreds[1].matches({SVal}, UndefValue::get(Int64Ty)));
468-
EXPECT_FALSE(IVOp.SourcePreds[2].matches({SVal, UndefValue::get(Int32Ty)},
465+
EXPECT_TRUE(IVOp.SourcePreds[1].matches({SVal}, PoisonValue::get(Int8PtrTy)));
466+
EXPECT_TRUE(IVOp.SourcePreds[1].matches({SVal}, PoisonValue::get(Int32Ty)));
467+
EXPECT_FALSE(IVOp.SourcePreds[1].matches({SVal}, PoisonValue::get(Int64Ty)));
468+
EXPECT_FALSE(IVOp.SourcePreds[2].matches({SVal, PoisonValue::get(Int32Ty)},
469469
ConstantInt::get(Int32Ty, 0)));
470-
EXPECT_TRUE(IVOp.SourcePreds[2].matches({SVal, UndefValue::get(Int32Ty)},
470+
EXPECT_TRUE(IVOp.SourcePreds[2].matches({SVal, PoisonValue::get(Int32Ty)},
471471
ConstantInt::get(Int32Ty, 1)));
472472

473473
EXPECT_THAT(IVOp.SourcePreds[1].generate({SVal}, {}),

0 commit comments

Comments
 (0)