[PATCH] D64053: [Verifier] add test case for callbr

Nick Desaulniers via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 1 18:13:21 PDT 2019


nickdesaulniers created this revision.
nickdesaulniers added reviewers: craig.topper, chandlerc.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

Check the list of indirect targets; if there's an indirect target
that's not also listed in the operand list, we have a problem.

I'm seeing something funny going on in a particular transform. This
added check is helping me pinpoint it in opt.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64053

Files:
  llvm/lib/IR/Verifier.cpp
  llvm/test/Verifier/callbr.ll


Index: llvm/test/Verifier/callbr.ll
===================================================================
--- /dev/null
+++ llvm/test/Verifier/callbr.ll
@@ -0,0 +1,15 @@
+; RUN: not opt -verify -S < %s 2>&1 | FileCheck %s
+
+; CHECK: Did not find indirect destination in callbr operand list
+
+define i32 @test_asm_goto(i32 %x){
+entry:
+  callbr void asm "", "r,X"(i32 %x, i8* blockaddress(@test_asm_goto, %not_in_indirect_list)) to label %fallthrough [label %indirect]
+
+fallthrough:
+  ret i32 1
+indirect:
+  ret i32 0
+not_in_indirect_list:
+  ret i32 2
+}
Index: llvm/lib/IR/Verifier.cpp
===================================================================
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -2487,6 +2487,17 @@
         Assert(CBI.getOperand(i) != CBI.getOperand(j),
                "Duplicate callbr destination!", &CBI);
   }
+  for (auto *BB : CBI.getIndirectDests()) {
+    BlockAddress *BA = BlockAddress::get(BB);
+    bool Found = false;
+    for (unsigned i = 0, e = CBI.getNumOperands(); i != e; ++i)
+      if (CBI.getOperand(i) == BA) {
+        Found = true;
+        break;
+      }
+    Assert(Found, "Did not find indirect destination in callbr operand list",
+           &CBI);
+  }
 
   visitTerminator(CBI);
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64053.207451.patch
Type: text/x-patch
Size: 1260 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190702/d4f5d91d/attachment.bin>


More information about the llvm-commits mailing list