[llvm] 1a3f158 - [FuzzMutate] Correct type cast and add unit test for FCmp

Peter Rong via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 21 16:37:41 PDT 2023


Author: Peter Rong
Date: 2023-04-21T16:37:36-07:00
New Revision: 1a3f158add6099914f943ac87fb3b0b8738f8ec8

URL: https://github.com/llvm/llvm-project/commit/1a3f158add6099914f943ac87fb3b0b8738f8ec8
DIFF: https://github.com/llvm/llvm-project/commit/1a3f158add6099914f943ac87fb3b0b8738f8ec8.diff

LOG: [FuzzMutate] Correct type cast and add unit test for FCmp

This revision fixes an incorrect type cast from Instruction to ICmpInstr, which should have been to FCmpInstr instead. It turns out that StrategiesTest.cpp was missing a test case for InstModificationIRStrategy and FCmp, which is also now implemented in this revision. After this revision, [[ https://reviews.llvm.org/D148854 | llvm-stress in D148854 ]] no longer crashes randomly.

Reviewed By: Peter

Differential Revision: https://reviews.llvm.org/D148972

Added: 
    

Modified: 
    llvm/lib/FuzzMutate/IRMutator.cpp
    llvm/unittests/FuzzMutate/StrategiesTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/FuzzMutate/IRMutator.cpp b/llvm/lib/FuzzMutate/IRMutator.cpp
index b896e3ca93fc6..2d6c83e49a81c 100644
--- a/llvm/lib/FuzzMutate/IRMutator.cpp
+++ b/llvm/lib/FuzzMutate/IRMutator.cpp
@@ -243,7 +243,7 @@ void InstModificationIRStrategy::mutate(Instruction &Inst,
     break;
 
   case Instruction::FCmp:
-    CI = cast<ICmpInst>(&Inst);
+    CI = cast<FCmpInst>(&Inst);
     for (unsigned p = CmpInst::FIRST_FCMP_PREDICATE;
          p <= CmpInst::LAST_FCMP_PREDICATE; p++) {
       Modifications.push_back(

diff  --git a/llvm/unittests/FuzzMutate/StrategiesTest.cpp b/llvm/unittests/FuzzMutate/StrategiesTest.cpp
index 5b87b9c6a7b87..1de027c43e49d 100644
--- a/llvm/unittests/FuzzMutate/StrategiesTest.cpp
+++ b/llvm/unittests/FuzzMutate/StrategiesTest.cpp
@@ -245,6 +245,31 @@ TEST(InstModificationIRStrategyTest, ICmp) {
   EXPECT_TRUE(FoundNE);
 }
 
+TEST(InstModificationIRStrategyTest, FCmp) {
+  LLVMContext Ctx;
+  StringRef Source = "\n\
+      define i1 @test(float %x) {\n\
+        %a = fcmp oeq float %x, 10.0\n\
+        ret i1 %a\n\
+      }";
+
+  auto Mutator = createMutator<InstModificationIRStrategy>();
+  ASSERT_TRUE(Mutator);
+
+  auto M = parseAssembly(Source.data(), Ctx);
+  auto &F = *M->begin();
+  CmpInst *CI = cast<CmpInst>(&*F.begin()->begin());
+  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);
+    EXPECT_TRUE(!verifyModule(*M, &errs()));
+    FoundONE |= CI->getPredicate() == CmpInst::FCMP_ONE;
+  }
+
+  EXPECT_TRUE(FoundONE);
+}
+
 TEST(InstModificationIRStrategyTest, GEP) {
   LLVMContext Ctx;
   StringRef Source = "\n\


        


More information about the llvm-commits mailing list