mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
sema: Fix overflow when analyzing an inline switch prong range that ends on the maximum value of the switched type
This commit is contained in:
parent
9d66481e3d
commit
5fc5e4fbe0
2 changed files with 14 additions and 0 deletions
|
|
@ -11646,6 +11646,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
|
|||
cases_extra.appendAssumeCapacity(@intCast(u32, case_block.instructions.items.len));
|
||||
cases_extra.appendAssumeCapacity(@intFromEnum(item_ref));
|
||||
cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);
|
||||
|
||||
if (item.compareScalar(.eq, item_last, operand_ty, mod)) break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -785,3 +785,15 @@ test "switch pointer capture peer type resolution" {
|
|||
try expectEqual(U{ .a = 111 }, ua);
|
||||
try expectEqual(U{ .b = 222 }, ub);
|
||||
}
|
||||
|
||||
test "inline switch range that includes the maximum value of the switched type" {
|
||||
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
||||
|
||||
const inputs: [3]u8 = .{ 0, 254, 255 };
|
||||
for (inputs) |input| {
|
||||
switch (input) {
|
||||
inline 254...255 => |val| try expectEqual(input, val),
|
||||
else => |val| try expectEqual(input, val),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue