[Mlir-commits] [mlir] [MLIR] Fix SCF verifier crash (PR #153974)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sat Aug 16 12:00:13 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir-scf

Author: Mehdi Amini (joker-eph)

<details>
<summary>Changes</summary>

An operand of the nested yield op can be null and hasn't been verified yet when processing the enclosing operation. Using `getResultTypes()` will dereference this null Value and crash in the verifier.

---
Full diff: https://github.com/llvm/llvm-project/pull/153974.diff


1 Files Affected:

- (modified) mlir/lib/Dialect/SCF/IR/SCF.cpp (+5-3) 


``````````diff
diff --git a/mlir/lib/Dialect/SCF/IR/SCF.cpp b/mlir/lib/Dialect/SCF/IR/SCF.cpp
index 89731de1df053..fd5b2a8e852da 100644
--- a/mlir/lib/Dialect/SCF/IR/SCF.cpp
+++ b/mlir/lib/Dialect/SCF/IR/SCF.cpp
@@ -4237,13 +4237,15 @@ LogicalResult scf::IndexSwitchOp::verify() {
     }
     for (auto [idx, result, operand] :
          llvm::zip(llvm::seq<unsigned>(0, getNumResults()), getResultTypes(),
-                   yield.getOperandTypes())) {
-      if (result == operand)
+                   yield.getOperands())) {
+      if (!operand)
+        return yield.emitOpError() << "operand " << idx << " is null\n";
+      if (result == operand.getType())
         continue;
       return (emitOpError("expected result #")
               << idx << " of each region to be " << result)
                  .attachNote(yield.getLoc())
-             << name << " returns " << operand << " here";
+             << name << " returns " << operand.getType() << " here";
     }
     return success();
   };

``````````

</details>


https://github.com/llvm/llvm-project/pull/153974


More information about the Mlir-commits mailing list