[Mlir-commits] [mlir] a6559b4 - Fix verifier crashing on some invalid IR

Mehdi Amini llvmlistbot at llvm.org
Wed Jun 16 12:36:40 PDT 2021


Author: Mehdi Amini
Date: 2021-06-16T19:36:28Z
New Revision: a6559b42cee2a1a34bd75cf78a70c64429fb5cf8

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

LOG: Fix verifier crashing on some invalid IR

In a region with multiple blocks the verifier will try to look for
dominance and may get successor list for blocks, even though a block
may be empty or does not end with a terminator.

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

Added: 
    

Modified: 
    mlir/lib/IR/Block.cpp
    mlir/test/IR/invalid.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/IR/Block.cpp b/mlir/lib/IR/Block.cpp
index d053788067763..364173d3c1bee 100644
--- a/mlir/lib/IR/Block.cpp
+++ b/mlir/lib/IR/Block.cpp
@@ -346,8 +346,8 @@ unsigned PredecessorIterator::getSuccessorIndex() const {
 SuccessorRange::SuccessorRange() : SuccessorRange(nullptr, 0) {}
 
 SuccessorRange::SuccessorRange(Block *block) : SuccessorRange() {
-  if (!llvm::hasSingleElement(*block->getParent())) {
-    Operation *term = block->getTerminator();
+  if (!block->empty() && !llvm::hasSingleElement(*block->getParent())) {
+    Operation *term = &block->back();
     if ((count = term->getNumSuccessors()))
       base = term->getBlockOperands().data();
   }

diff  --git a/mlir/test/IR/invalid.mlir b/mlir/test/IR/invalid.mlir
index 24b9dc80cee43..818f4584eb270 100644
--- a/mlir/test/IR/invalid.mlir
+++ b/mlir/test/IR/invalid.mlir
@@ -176,6 +176,16 @@ func @no_return() {
   %y = constant 1 : i32  // expected-error {{block with no terminator}}
 }
 
+// -----
+
+func @no_terminator() {
+  br ^bb1
+^bb1:
+  %x = constant 0 : i32
+  %y = constant 1 : i32  // expected-error {{block with no terminator}}
+}
+
+
 // -----
 
 "       // expected-error {{expected}}


        


More information about the Mlir-commits mailing list