Skip to content

Commit 88a643d

Browse files
committed
Strict type-class validation in instruction_has_valid_types
Remove TypeClass::Other escape that allowed ops like IAdd/IMul to pass validation when their result type was uncategorized. Now ops requiring a specific type class (Int, Float, Bool) must match exactly, causing the optimizer to fall back to the original valid instruction when a rewrite produces a type mismatch.
1 parent 2047cef commit 88a643d

File tree

1 file changed

+4
-3
lines changed
  • rust/spirv-tools-opt/src/direct

1 file changed

+4
-3
lines changed

rust/spirv-tools-opt/src/direct/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2390,14 +2390,15 @@ fn instruction_has_valid_types(
23902390
) -> bool {
23912391
let op = inst.class.opcode;
23922392

2393-
// Check result type
2393+
// Check result type: if the opcode requires a specific type class,
2394+
// the result type MUST match (no TypeClass::Other escape).
23942395
if let (Some(required), Some(result_type)) = (required_result_type_class(op), inst.result_type)
23952396
{
23962397
let actual = type_classes
23972398
.get(&result_type)
23982399
.copied()
23992400
.unwrap_or(TypeClass::Other);
2400-
if actual != required && actual != TypeClass::Other {
2401+
if actual != required {
24012402
return false;
24022403
}
24032404
}
@@ -2411,7 +2412,7 @@ fn instruction_has_valid_types(
24112412
.get(&operand_type)
24122413
.copied()
24132414
.unwrap_or(TypeClass::Other);
2414-
if actual != required_op_class && actual != TypeClass::Other {
2415+
if actual != required_op_class {
24152416
return false;
24162417
}
24172418
}

0 commit comments

Comments
 (0)