[PATCH] D148853: [FuzzMutate] Skip EHPad to avoid crash during mutation

Henry Yu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 26 10:36:25 PDT 2023


HazyFish updated this revision to Diff 517234.
HazyFish added a comment.

Fix format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148853

Files:
  llvm/include/llvm/FuzzMutate/IRMutator.h
  llvm/lib/FuzzMutate/IRMutator.cpp
  llvm/lib/FuzzMutate/RandomIRBuilder.cpp
  llvm/unittests/FuzzMutate/StrategiesTest.cpp


Index: llvm/unittests/FuzzMutate/StrategiesTest.cpp
===================================================================
--- llvm/unittests/FuzzMutate/StrategiesTest.cpp
+++ llvm/unittests/FuzzMutate/StrategiesTest.cpp
@@ -640,4 +640,30 @@
     }";
   VerifyBlockShuffle(Source);
 }
+
+TEST(AllStrategies, SkipEHPad) {
+  StringRef Source = "\n\
+    define void @f(i32 %x) personality ptr @__CxxFrameHandler3 { \n\
+    entry: \n\
+      invoke void @g() to label %try.cont unwind label %catch.dispatch \n\
+    catch.dispatch: \n\
+      %0 = catchswitch within none [label %catch] unwind to caller \n\
+    catch: \n\
+      %1 = catchpad within %0 [ptr null, i32 64, ptr null] \n\
+      catchret from %1 to label %try.cont \n\
+    try.cont: \n\
+      ret void \n\
+    } \n\
+    declare void @g() \n\
+    declare i32 @__CxxFrameHandler3(...) \n\
+    ";
+
+  mutateAndVerifyModule<ShuffleBlockStrategy>(Source);
+  mutateAndVerifyModule<InsertPHIStrategy>(Source);
+  mutateAndVerifyModule<InsertFunctionStrategy>(Source);
+  mutateAndVerifyModule<InsertCFGStrategy>(Source);
+  mutateAndVerifyModule<SinkInstructionStrategy>(Source);
+  mutateAndVerifyModule<InjectorIRStrategy>(Source);
+  mutateAndVerifyModule<InstModificationIRStrategy>(Source);
+}
 } // namespace
Index: llvm/lib/FuzzMutate/RandomIRBuilder.cpp
===================================================================
--- llvm/lib/FuzzMutate/RandomIRBuilder.cpp
+++ llvm/lib/FuzzMutate/RandomIRBuilder.cpp
@@ -264,7 +264,7 @@
   case Instruction::CallBr: {
     const CallBase *II = cast<CallBase>(I);
     const Function *Callee = II->getCalledFunction();
-    return !Callee->hasParamAttribute(OperandNo, Attribute::ImmArg);
+    return Callee && !Callee->hasParamAttribute(OperandNo, Attribute::ImmArg);
   }
   default:
     break;
Index: llvm/lib/FuzzMutate/IRMutator.cpp
===================================================================
--- llvm/lib/FuzzMutate/IRMutator.cpp
+++ llvm/lib/FuzzMutate/IRMutator.cpp
@@ -45,7 +45,10 @@
 }
 
 void IRMutationStrategy::mutate(Function &F, RandomIRBuilder &IB) {
-  mutate(*makeSampler(IB.Rand, make_pointer_range(F)).getSelection(), IB);
+  auto Range = make_filter_range(make_pointer_range(F),
+                                 [](BasicBlock *BB) { return !BB->isEHPad(); });
+
+  mutate(*makeSampler(IB.Rand, Range).getSelection(), IB);
 }
 
 void IRMutationStrategy::mutate(BasicBlock &BB, RandomIRBuilder &IB) {
@@ -566,7 +569,6 @@
 }
 
 void ShuffleBlockStrategy::mutate(BasicBlock &BB, RandomIRBuilder &IB) {
-
   SmallPtrSet<Instruction *, 8> AliveInsts;
   for (auto &I : make_early_inc_range(make_range(
            BB.getFirstInsertionPt(), BB.getTerminator()->getIterator()))) {
Index: llvm/include/llvm/FuzzMutate/IRMutator.h
===================================================================
--- llvm/include/llvm/FuzzMutate/IRMutator.h
+++ llvm/include/llvm/FuzzMutate/IRMutator.h
@@ -81,6 +81,7 @@
                                                         RandomIRBuilder &IB);
 
 public:
+  InjectorIRStrategy() : Operations(getDefaultOps()) {}
   InjectorIRStrategy(std::vector<fuzzerop::OpDescriptor> &&Operations)
       : Operations(std::move(Operations)) {}
   static std::vector<fuzzerop::OpDescriptor> getDefaultOps();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148853.517234.patch
Type: text/x-patch
Size: 3269 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230426/1764c51d/attachment-0001.bin>


More information about the llvm-commits mailing list