diff --git a/llvm/lib/FuzzMutate/IRMutator.cpp b/llvm/lib/FuzzMutate/IRMutator.cpp --- a/llvm/lib/FuzzMutate/IRMutator.cpp +++ b/llvm/lib/FuzzMutate/IRMutator.cpp @@ -360,7 +360,8 @@ auto RS = makeSampler(IB.Rand, Functions); Function *F = RS.getSelection(); - if (!F) { + auto IsMetadataTy = [](Type *T) { return T->isMetadataTy(); }; + if (!F || any_of(F->getFunctionType()->params(), IsMetadataTy)) { F = IB.createFunctionDeclaration(*M); } diff --git a/llvm/tools/llvm-stress/llvm-stress.cpp b/llvm/tools/llvm-stress/llvm-stress.cpp --- a/llvm/tools/llvm-stress/llvm-stress.cpp +++ b/llvm/tools/llvm-stress/llvm-stress.cpp @@ -178,7 +178,7 @@ srand(Seed); auto Mutator = createCustomMutator(); for (unsigned i = 0; i < RepeatCL; i++) { - Mutator->mutateModule(*M, rand(), M->size(), MaxSizeCL); + Mutator->mutateModule(*M, rand(), MaxSizeCL); } // Figure out what stream we are supposed to write to... diff --git a/llvm/unittests/FuzzMutate/StrategiesTest.cpp b/llvm/unittests/FuzzMutate/StrategiesTest.cpp --- a/llvm/unittests/FuzzMutate/StrategiesTest.cpp +++ b/llvm/unittests/FuzzMutate/StrategiesTest.cpp @@ -374,7 +374,7 @@ VerfyDivDidntShuffle(Source); } -TEST(FunctionIRStrategy, Func) { +TEST(InsertFunctionStrategy, Func) { LLVMContext Ctx; const char *Source = ""; auto Mutator = createMutator(); @@ -388,6 +388,22 @@ } } +TEST(InsertFunctionStrategy, AvoidCallingFunctionWithMetadataParam) { + LLVMContext Ctx; + StringRef Source = "\n\ + declare void @llvm.dbg.value(metadata %0, metadata %1, metadata %2)\n\ + define i32 @test(i32 %0) {\n\ + ret i32 %0 \n\ + }"; + auto Mutator = createMutator(); + auto M = parseAssembly(Source.data(), Ctx); + srand(Seed); + for (int i = 0; i < 100; i++) { + Mutator->mutateModule(*M, rand(), 1024); + EXPECT_TRUE(!verifyModule(*M, &errs())); + } +} + TEST(InstModificationIRStrategy, Exact) { LLVMContext Ctx; StringRef Source = "\n\