[PATCH] D150627: [FuzzMutate] Avoid calling function with metadata/token parameter/return type for `InsertFunctionStrategy`

Peter Rong via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 1 13:59:58 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG6a28d3c21d3a: [FuzzMutate] Avoid calling function with metadata/token parameter/return type… (authored by HazyFish, committed by Peter).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150627/new/

https://reviews.llvm.org/D150627

Files:
  llvm/lib/FuzzMutate/IRMutator.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,23 @@
   }
 }
 
+TEST(InsertFunctionStrategy, AvoidCallingFunctionWithSpecialParam) {
+  LLVMContext Ctx;
+  StringRef Source = "\n\
+      declare void @llvm.dbg.value(metadata %0, metadata %1, metadata %2)\n\
+      declare i1 @llvm.experimental.gc.result.i1(token %0)\n\
+      define i32 @test(i32 %0) gc \"statepoint-example\" {\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/lib/FuzzMutate/IRMutator.cpp
===================================================================
--- llvm/lib/FuzzMutate/IRMutator.cpp
+++ llvm/lib/FuzzMutate/IRMutator.cpp
@@ -360,7 +360,11 @@
 
   auto RS = makeSampler(IB.Rand, Functions);
   Function *F = RS.getSelection();
-  if (!F) {
+  auto IsUnsupportedTy = [](Type *T) {
+    return T->isMetadataTy() || T->isTokenTy();
+  };
+  if (!F || IsUnsupportedTy(F->getReturnType()) ||
+      any_of(F->getFunctionType()->params(), IsUnsupportedTy)) {
     F = IB.createFunctionDeclaration(*M);
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150627.527607.patch
Type: text/x-patch
Size: 1757 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230601/d4068727/attachment.bin>


More information about the llvm-commits mailing list