Type::getInt64Ty, Type::getFloatTy, Type::getDoubleTy};
std::vector<std::unique_ptr<IRMutationStrategy>> Strategies;
- Strategies.push_back(
- std::make_unique<InjectorIRStrategy>(
- InjectorIRStrategy::getDefaultOps()));
- Strategies.push_back(
- std::make_unique<InstDeleterIRStrategy>());
+ Strategies.push_back(std::make_unique<InjectorIRStrategy>(
+ InjectorIRStrategy::getDefaultOps()));
+ Strategies.push_back(std::make_unique<InstDeleterIRStrategy>());
Strategies.push_back(std::make_unique<InstModificationIRStrategy>());
return std::make_unique<IRMutator>(std::move(Types), std::move(Strategies));
uint8_t *Data, size_t Size, size_t MaxSize, unsigned int Seed) {
assert(Mutator &&
- "IR mutator should have been created during fuzzer initialization");
+ "IR mutator should have been created during fuzzer initialization");
LLVMContext Context;
auto M = parseAndVerify(Data, Size, Context);
return 0;
}
- Mutator->mutateModule(*M, Seed, Size, MaxSize);
+ Mutator->mutateModule(*M, Seed, MaxSize);
if (verifyModule(*M, &errs())) {
errs() << "mutation result doesn't pass verification\n";
// Avoid adding incorrect test cases to the corpus.
return 0;
}
-
+
std::string Buf;
{
raw_string_ostream OS(Buf);
}
if (Buf.size() > MaxSize)
return 0;
-
+
// There are some invariants which are not checked by the verifier in favor
// of having them checked by the parser. They may be considered as bugs in the
// verifier and should be fixed there. However until all of those are covered
// we want to check for them explicitly. Otherwise we will add incorrect input
- // to the corpus and this is going to confuse the fuzzer which will start
+ // to the corpus and this is going to confuse the fuzzer which will start
// exploration of the bitcode reader error handling code.
- auto NewM = parseAndVerify(
- reinterpret_cast<const uint8_t*>(Buf.data()), Buf.size(), Context);
+ auto NewM = parseAndVerify(reinterpret_cast<const uint8_t *>(Buf.data()),
+ Buf.size(), Context);
if (!NewM) {
errs() << "mutator failed to re-read the module\n";
#ifndef NDEBUG
abort();
}
-extern "C" LLVM_ATTRIBUTE_USED int LLVMFuzzerInitialize(
- int *argc, char ***argv) {
+extern "C" LLVM_ATTRIBUTE_USED int LLVMFuzzerInitialize(int *argc,
+ char ***argv) {
EnableDebugBuffering = true;
// Make sure we print the summary and the current unit when LLVM errors out.
auto M = parseAssembly(Source.data(), Ctx);
ASSERT_TRUE(M && !verifyModule(*M, &errs()));
- Mutator.mutateModule(*M, Seed, Source.size(), Source.size() + 100);
+ Mutator.mutateModule(*M, Seed, IRMutator::getModuleSize(*M) + 100);
EXPECT_TRUE(!verifyModule(*M, &errs()));
}
}
std::mt19937 mt(Seed);
std::uniform_int_distribution<int> RandInt(INT_MIN, INT_MAX);
for (int i = 0; i < repeat; i++) {
- Mutator->mutateModule(*M, RandInt(mt), Source.size(), Source.size() + 1024);
+ Mutator->mutateModule(*M, RandInt(mt), IRMutator::getModuleSize(*M) + 1024);
ASSERT_FALSE(verifyModule(*M, &errs()));
}
}
auto Mutator = createInjectorMutator();
ASSERT_TRUE(Mutator);
- Mutator->mutateModule(*M, Seed, 1, 1);
+ Mutator->mutateModule(*M, Seed, IRMutator::getModuleSize(*M) + 1);
EXPECT_TRUE(!verifyModule(*M, &errs()));
}
bool FoundNUW = false;
bool FoundNSW = false;
for (int i = 0; i < 100; ++i) {
- Mutator->mutateModule(*M, Seed + i, Source.size(), Source.size() + 100);
+ Mutator->mutateModule(*M, Seed + i, IRMutator::getModuleSize(*M) + 100);
EXPECT_TRUE(!verifyModule(*M, &errs()));
FoundNUW |= AddI->hasNoUnsignedWrap();
FoundNSW |= AddI->hasNoSignedWrap();
ASSERT_TRUE(M && !verifyModule(*M, &errs()));
bool FoundNE = false;
for (int i = 0; i < 100; ++i) {
- Mutator->mutateModule(*M, Seed + i, Source.size(), Source.size() + 100);
+ Mutator->mutateModule(*M, Seed + i, IRMutator::getModuleSize(*M) + 100);
EXPECT_TRUE(!verifyModule(*M, &errs()));
FoundNE |= CI->getPredicate() == CmpInst::ICMP_NE;
}
ASSERT_TRUE(M && !verifyModule(*M, &errs()));
bool FoundONE = false;
for (int i = 0; i < 100; ++i) {
- Mutator->mutateModule(*M, Seed + i, Source.size(), Source.size() + 100);
+ Mutator->mutateModule(*M, Seed + i, IRMutator::getModuleSize(*M) + 100);
EXPECT_TRUE(!verifyModule(*M, &errs()));
FoundONE |= CI->getPredicate() == CmpInst::FCMP_ONE;
}
ASSERT_TRUE(M && !verifyModule(*M, &errs()));
bool FoundInbounds = false;
for (int i = 0; i < 100; ++i) {
- Mutator->mutateModule(*M, Seed + i, Source.size(), Source.size() + 100);
+ Mutator->mutateModule(*M, Seed + i, IRMutator::getModuleSize(*M) + 100);
EXPECT_TRUE(!verifyModule(*M, &errs()));
FoundInbounds |= GEP->isInBounds();
}
ASSERT_TRUE(Inst->getOperand(ShuffleItems.second) ==
dyn_cast<Value>(F.getArg(ShuffleItems.second)));
- Mutator->mutateModule(*M, 0, Source.size(), Source.size() + 100);
+ Mutator->mutateModule(*M, 0, IRMutator::getModuleSize(*M) + 100);
ASSERT_TRUE(!verifyModule(*M, &errs()));
ASSERT_TRUE(Inst->getOperand(ShuffleItems.first) ==
EXPECT_TRUE(isa<Constant>(Inst->getOperand(0)));
EXPECT_TRUE(Inst->getOperand(1) == dyn_cast<Value>(F.getArg(0)));
- Mutator->mutateModule(*M, Seed, Source.size(), Source.size() + 100);
+ Mutator->mutateModule(*M, Seed, IRMutator::getModuleSize(*M) + 100);
EXPECT_TRUE(!verifyModule(*M, &errs()));
// Didn't shuffle.
auto M = parseAssembly(Source, Ctx);
srand(Seed);
for (int i = 0; i < 100; i++) {
- Mutator->mutateModule(*M, rand(), 0, 1024);
+ Mutator->mutateModule(*M, rand(), 1024);
EXPECT_TRUE(!verifyModule(*M, &errs()));
}
}
BinaryOperator *AShr = cast<BinaryOperator>(&*F.begin()->begin());
bool FoundExact = false;
for (int i = 0; i < 100; ++i) {
- Mutator->mutateModule(*M, RandInt(mt), Source.size(), Source.size() + 100);
+ Mutator->mutateModule(*M, RandInt(mt), IRMutator::getModuleSize(*M) + 100);
ASSERT_FALSE(verifyModule(*M, &errs()));
FoundExact |= AShr->isExact();
}
}
ASSERT_TRUE(M && !verifyModule(*M, &errs()));
for (int i = 0; i < 300; ++i) {
- Mutator->mutateModule(*M, RandInt(mt), Source.size(), Source.size() + 100);
+ Mutator->mutateModule(*M, RandInt(mt), IRMutator::getModuleSize(*M) + 100);
for (auto p : FPOpsHasFastMath)
FPOpsHasFastMath[p.first] |= p.first->getFastMathFlags().any();
ASSERT_FALSE(verifyModule(*M, &errs()));
std::mt19937 mt(Seed);
std::uniform_int_distribution<int> RandInt(INT_MIN, INT_MAX);
for (int i = 0; i < 100; i++) {
- Mutator->mutateModule(*M, RandInt(mt), Source.size(), Source.size() + 1024);
+ Mutator->mutateModule(*M, RandInt(mt), IRMutator::getModuleSize(*M) + 1024);
for (BasicBlock &BB : *F) {
int PostShuffleIntCnt = BB.size();
EXPECT_EQ(PostShuffleIntCnt, PreShuffleInstCnt[&BB]);