[llvm] r320571 - [FuzzMutate] Correctly split landingpad blocks

Igor Laevsky via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 13 03:45:53 PST 2017


Author: igor.laevsky
Date: Wed Dec 13 03:45:53 2017
New Revision: 320571

URL: http://llvm.org/viewvc/llvm-project?rev=320571&view=rev
Log:
[FuzzMutate] Correctly split landingpad blocks

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


Modified:
    llvm/trunk/lib/FuzzMutate/Operations.cpp
    llvm/trunk/unittests/FuzzMutate/OperationsTest.cpp

Modified: llvm/trunk/lib/FuzzMutate/Operations.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/FuzzMutate/Operations.cpp?rev=320571&r1=320570&r2=320571&view=diff
==============================================================================
--- llvm/trunk/lib/FuzzMutate/Operations.cpp (original)
+++ llvm/trunk/lib/FuzzMutate/Operations.cpp Wed Dec 13 03:45:53 2017
@@ -142,9 +142,14 @@ OpDescriptor llvm::fuzzerop::splitBlockD
   auto buildSplitBlock = [](ArrayRef<Value *> Srcs, Instruction *Inst) {
     BasicBlock *Block = Inst->getParent();
     BasicBlock *Next = Block->splitBasicBlock(Inst, "BB");
+
+    // If it was an exception handling block, we are done.
+    if (Block->isEHPad())
+      return nullptr;
+
+    // Loop back on this block by replacing the unconditional forward branch
+    // with a conditional with a backedge.
     if (Block != &Block->getParent()->getEntryBlock()) {
-      // Loop back on this block by replacing the unconditional forward branch
-      // with a conditional with a backedge.
       BranchInst::Create(Block, Next, Srcs[0], Block->getTerminator());
       Block->getTerminator()->eraseFromParent();
 

Modified: llvm/trunk/unittests/FuzzMutate/OperationsTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/FuzzMutate/OperationsTest.cpp?rev=320571&r1=320570&r2=320571&view=diff
==============================================================================
--- llvm/trunk/unittests/FuzzMutate/OperationsTest.cpp (original)
+++ llvm/trunk/unittests/FuzzMutate/OperationsTest.cpp Wed Dec 13 03:45:53 2017
@@ -211,6 +211,35 @@ TEST(OperationsTest, SplitBlock) {
   EXPECT_FALSE(verifyModule(M, &errs()));
 }
 
+TEST(OperationsTest, SplitEHBlock) {
+  // Check that we will not try to branch back to the landingpad block using
+  // regular branch instruction
+
+  LLVMContext Ctx;
+  const char *SourceCode =
+      "declare i32* @f()"
+      "declare i32 @personality_function()"
+      "define i32* @test() personality i32 ()* @personality_function {\n"
+      "entry:\n"
+      "  %val = invoke i32* @f()\n"
+      "          to label %normal unwind label %exceptional\n"
+      "normal:\n"
+      "  ret i32* %val\n"
+      "exceptional:\n"
+      "  %landing_pad4 = landingpad token cleanup\n"
+      "  ret i32* undef\n"
+      "}";
+  auto M = parseAssembly(SourceCode, Ctx);
+
+  // Get the landingpad block
+  BasicBlock &BB = *std::next(M->getFunction("test")->begin(), 2);
+
+  fuzzerop::OpDescriptor Descr = fuzzerop::splitBlockDescriptor(1);
+
+  Descr.BuilderFunc({ConstantInt::getTrue(Ctx)},&*BB.getFirstInsertionPt());
+  ASSERT_TRUE(!verifyModule(*M, &errs()));
+}
+
 TEST(OperationsTest, SplitBlockWithPhis) {
   LLVMContext Ctx;
 




More information about the llvm-commits mailing list