[Mlir-commits] [mlir] 569c21a - [mlir][SPIR-V] Fix empty optional deref in spirv.Switch verifier (#203561)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sun Jun 14 20:14:45 PDT 2026


Author: Arseniy Obolenskiy
Date: 2026-06-15T05:14:40+02:00
New Revision: 569c21a4a5fd24b14a05bf9e8ea08a3694fbb0d3

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

LOG: [mlir][SPIR-V] Fix empty optional deref in spirv.Switch verifier (#203561)

Added: 
    

Modified: 
    mlir/lib/Dialect/SPIRV/IR/ControlFlowOps.cpp
    mlir/test/Dialect/SPIRV/IR/control-flow-ops.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/SPIRV/IR/ControlFlowOps.cpp b/mlir/lib/Dialect/SPIRV/IR/ControlFlowOps.cpp
index 5c2d538a00b17..0ad88dee9fe9e 100644
--- a/mlir/lib/Dialect/SPIRV/IR/ControlFlowOps.cpp
+++ b/mlir/lib/Dialect/SPIRV/IR/ControlFlowOps.cpp
@@ -266,12 +266,14 @@ LogicalResult SwitchOp::verify() {
   if (!literals && targets.empty())
     return success();
 
-  Type selectorType = getSelector().getType();
-  Type literalType = literals->getType().getElementType();
-  if (literalType != selectorType)
-    return emitOpError() << "'selector' type (" << selectorType
-                         << ") should match literals type (" << literalType
-                         << ")";
+  if (literals) {
+    Type selectorType = getSelector().getType();
+    Type literalType = literals->getType().getElementType();
+    if (literalType != selectorType)
+      return emitOpError() << "'selector' type (" << selectorType
+                           << ") should match literals type (" << literalType
+                           << ")";
+  }
 
   if (literals && literals->size() != static_cast<int64_t>(targets.size()))
     return emitOpError() << "number of literals (" << literals->size()

diff  --git a/mlir/test/Dialect/SPIRV/IR/control-flow-ops.mlir b/mlir/test/Dialect/SPIRV/IR/control-flow-ops.mlir
index 81dce9822db48..189040a0745fc 100644
--- a/mlir/test/Dialect/SPIRV/IR/control-flow-ops.mlir
+++ b/mlir/test/Dialect/SPIRV/IR/control-flow-ops.mlir
@@ -1143,6 +1143,22 @@ func.func @switch_operands(%selector : i32, %operand : i32) {
   spirv.Return
 }
 
+func.func @switch_targets_no_literals(%selector: i32) -> () {
+  // CHECK: spirv.Switch {{%.*}} : i32, [
+  // CHECK-NEXT: default: ^bb1
+  "spirv.Switch"(%selector)[^default, ^target]
+    {case_operand_segments = array<i32: 0>,
+     operandSegmentSizes = array<i32: 1, 0, 0>} : (i32) -> ()
+^default:
+  spirv.Branch ^merge
+
+^target:
+  spirv.Branch ^merge
+
+^merge:
+  spirv.Return
+}
+
 // -----
 
 func.func @switch_float_selector(%selector: f32) -> () {


        


More information about the Mlir-commits mailing list