[PATCH] D150627: [FuzzMutate] Avoid calling function with metadata parameter for `InsertFunctionStrategy`
Henry Yu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon May 15 17:01:18 PDT 2023
HazyFish created this revision.
HazyFish added a reviewer: Peter.
Herald added a subscriber: hiraditya.
Herald added a project: All.
HazyFish requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
When there is a function with metadata parameter, `InsertFunctionStrategy` will crash.
This patch fixes the problem by falling back to create function declaration when the sampled function contains parameter of metadata type.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D150627
Files:
llvm/lib/FuzzMutate/IRMutator.cpp
llvm/tools/llvm-stress/llvm-stress.cpp
llvm/unittests/FuzzMutate/StrategiesTest.cpp
Index: llvm/unittests/FuzzMutate/StrategiesTest.cpp
===================================================================
--- llvm/unittests/FuzzMutate/StrategiesTest.cpp
+++ 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<InsertFunctionStrategy>();
@@ -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<InsertFunctionStrategy>();
+ 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\
Index: llvm/tools/llvm-stress/llvm-stress.cpp
===================================================================
--- llvm/tools/llvm-stress/llvm-stress.cpp
+++ 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...
Index: llvm/lib/FuzzMutate/IRMutator.cpp
===================================================================
--- llvm/lib/FuzzMutate/IRMutator.cpp
+++ 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);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150627.522388.patch
Type: text/x-patch
Size: 2092 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230516/a48dffaf/attachment.bin>
More information about the llvm-commits
mailing list