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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Aug 18 03:48:59 PDT 2025


Author: Mehdi Amini
Date: 2025-08-18T12:48:55+02:00
New Revision: cfe5975eaf0adf333c8210925318a7a43b1750de

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

LOG: [MLIR] Fix SCF verifier crash (#153974)

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.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/SCF/IR/SCF.cpp b/mlir/lib/Dialect/SCF/IR/SCF.cpp
index 89731de1df053..0dbc041d231a2 100644
--- a/mlir/lib/Dialect/SCF/IR/SCF.cpp
+++ b/mlir/lib/Dialect/SCF/IR/SCF.cpp
@@ -4236,14 +4236,15 @@ LogicalResult scf::IndexSwitchOp::verify() {
              << "see yield operation here";
     }
     for (auto [idx, result, operand] :
-         llvm::zip(llvm::seq<unsigned>(0, getNumResults()), getResultTypes(),
-                   yield.getOperandTypes())) {
-      if (result == operand)
+         llvm::enumerate(getResultTypes(), 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();
   };


        


More information about the Mlir-commits mailing list