authorgravatar for sinon@vortan.devDavid Rubin <sinon@vortan.dev> 2026-06-09 18:37:12-07:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-06-18 16:42:32+02:00
log805e51389ba89ad1460efafcf2e0a373008d72bc
treed2112d473cd0510c9576e6f244dba754536893fe
parent5d3be4fbe8372e357a25a7e24e4825425de086fe

Sema: catch missing @intCast case


4 files changed, 45 insertions(+), 23 deletions(-)

src/Sema.zig+1-1
...@@ -9293,7 +9293,7 @@ fn intCast(...@@ -9293,7 +9293,7 @@ fn intCast(
9293 break :ok all_in_range;9293 break :ok all_in_range;
9294 } else ok: {9294 } else ok: {
9295 const zero_inst = Air.internedToRef((try pt.intValue(operand_ty, 0)).toIntern());9295 const zero_inst = Air.internedToRef((try pt.intValue(operand_ty, 0)).toIntern());
9296 const is_in_range = try block.addBinOp(.cmp_lte, operand, zero_inst);9296 const is_in_range = try block.addBinOp(.cmp_eq, operand, zero_inst);
9297 break :ok is_in_range;9297 break :ok is_in_range;
9298 };9298 };
9299 try sema.addSafetyCheck(block, src, ok, .integer_out_of_bounds);9299 try sema.addSafetyCheck(block, src, ok, .integer_out_of_bounds);
test/cases/safety/@intCast negative to u0.zig created+22
...@@ -0,0 +1,22 @@
1const std = @import("std");
2
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
4 _ = stack_trace;
5 if (std.mem.eql(u8, message, "integer does not fit in destination type")) {
6 std.process.exit(0);
7 }
8 std.process.exit(1);
9}
10
11pub fn main() !void {
12 bar(1, -1);
13 return error.TestFailed;
14}
15
16fn bar(one: u1, not_zero: i32) void {
17 const x = one << @intCast(not_zero);
18 _ = x;
19}
20// run
21// backend=selfhosted,llvm
22// target=x86_64-linux,aarch64-linux
test/cases/safety/@intCast positive to u0.zig created+22
...@@ -0,0 +1,22 @@
1const std = @import("std");
2
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
4 _ = stack_trace;
5 if (std.mem.eql(u8, message, "integer does not fit in destination type")) {
6 std.process.exit(0);
7 }
8 std.process.exit(1);
9}
10
11pub fn main() !void {
12 bar(1, 1);
13 return error.TestFailed;
14}
15
16fn bar(one: u1, not_zero: i32) void {
17 const x = one << @intCast(not_zero);
18 _ = x;
19}
20// run
21// backend=selfhosted,llvm
22// target=x86_64-linux,aarch64-linux
test/cases/safety/@intCast to u0.zig deleted-22
...@@ -1,22 +0,0 @@
1const std = @import("std");
2
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
4 _ = stack_trace;
5 if (std.mem.eql(u8, message, "integer does not fit in destination type")) {
6 std.process.exit(0);
7 }
8 std.process.exit(1);
9}
10
11pub fn main() !void {
12 bar(1, 1);
13 return error.TestFailed;
14}
15
16fn bar(one: u1, not_zero: i32) void {
17 const x = one << @intCast(not_zero);
18 _ = x;
19}
20// run
21// backend=selfhosted,llvm
22// target=x86_64-linux,aarch64-linux