[Mlir-commits] [mlir] cffd7b1 - [mlir][scf] Fixes IndexSwitchOp verifier crash

Mehdi Amini llvmlistbot at llvm.org
Tue Dec 13 01:42:49 PST 2022


Author: Mehdi Amini
Date: 2022-12-13T09:42:34Z
New Revision: cffd7b144b6df9ced6f4d6f477a63516dbdf3c4b

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

LOG: [mlir][scf] Fixes IndexSwitchOp verifier crash

Fixes #59460

Added: 
    

Modified: 
    mlir/lib/Dialect/SCF/IR/SCF.cpp
    mlir/test/Dialect/SCF/invalid.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/SCF/IR/SCF.cpp b/mlir/lib/Dialect/SCF/IR/SCF.cpp
index a7ca5783d67d6..0ec89c06f77ea 100644
--- a/mlir/lib/Dialect/SCF/IR/SCF.cpp
+++ b/mlir/lib/Dialect/SCF/IR/SCF.cpp
@@ -3477,9 +3477,12 @@ LogicalResult scf::IndexSwitchOp::verify() {
   for (int64_t value : getCases())
     if (!valueSet.insert(value).second)
       return emitOpError("has duplicate case value: ") << value;
-
   auto verifyRegion = [&](Region &region, const Twine &name) -> LogicalResult {
-    auto yield = cast<YieldOp>(region.front().getTerminator());
+    auto yield = dyn_cast<YieldOp>(region.front().back());
+    if (!yield)
+      return emitOpError("expected region to end with scf.yield, but got ")
+             << region.front().back().getName();
+
     if (yield.getNumOperands() != getNumResults()) {
       return (emitOpError("expected each region to return ")
               << getNumResults() << " values, but " << name << " returns "

diff  --git a/mlir/test/Dialect/SCF/invalid.mlir b/mlir/test/Dialect/SCF/invalid.mlir
index 5fbb0f735d272..c97514f3ed167 100644
--- a/mlir/test/Dialect/SCF/invalid.mlir
+++ b/mlir/test/Dialect/SCF/invalid.mlir
@@ -641,3 +641,14 @@ func.func @switch_wrong_types(%arg0: index, %arg1: i32) {
   }
   return
 }
+
+// -----
+
+func.func @switch_missing_terminator(%arg0: index, %arg1: i32) {
+  // expected-error @below {{'scf.index_switch' op expected region to end with scf.yield, but got func.return}}
+  "scf.index_switch"(%arg0) ({
+    "scf.yield"() : () -> ()
+  }, {
+    return
+  }) {cases = array<i64: 1>} : (index) -> ()
+}


        


More information about the Mlir-commits mailing list