authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-06-01 07:41:24+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-06-01 12:10:57+01:00
logc1a5caa4545264b476951e844818f2abe103f41c
treefcacbb6cb46d76b9bb31a20a7c2149cb3802b7d7
parent6daa37ded905431f3a25508a42590031b0905ab9
signaturelock-open Commit is signed but in an unrecognized format.

compiler: combine `@intCast` safety checks

`castTruncatedData` was a poorly worded error (all shrinking casts "truncate bits", it's just that we assume those bits to be zext/sext of the other bits!), and `negativeToUnsigned` was a pointless distinction which forced the compiler to emit worse code (since two separate safety checks were required for casting e.g. 'i32' to 'u16') and wasn't even implemented correctly. This commit combines those safety panics into one function, `integerOutOfBounds`. The name maybe isn't perfect, but that's not hugely important; what matters is the new default message, which is clearer than the old ones: "integer does not fit in destination type".

20 files changed, 46 insertions(+), 74 deletions(-)

doc/langref/test_intCast_builtin.zig+1-1
...@@ -5,4 +5,4 @@ test "integer cast panic" {...@@ -5,4 +5,4 @@ test "integer cast panic" {
5 _ = b;5 _ = b;
6}6}
77
8// test_error=cast truncated bits8// test_error=integer does not fit in destination type
lib/std/debug.zig+6-6
...@@ -78,13 +78,9 @@ pub fn FullPanic(comptime panicFn: fn ([]const u8, ?usize) noreturn) type {...@@ -78,13 +78,9 @@ pub fn FullPanic(comptime panicFn: fn ([]const u8, ?usize) noreturn) type {
78 @branchHint(.cold);78 @branchHint(.cold);
79 call("invalid error code", @returnAddress());79 call("invalid error code", @returnAddress());
80 }80 }
81 pub fn castTruncatedData() noreturn {81 pub fn integerOutOfBounds() noreturn {
82 @branchHint(.cold);82 @branchHint(.cold);
83 call("integer cast truncated bits", @returnAddress());83 call("integer does not fit in destination type", @returnAddress());
84 }
85 pub fn negativeToUnsigned() noreturn {
86 @branchHint(.cold);
87 call("attempt to cast negative value to unsigned integer", @returnAddress());
88 }84 }
89 pub fn integerOverflow() noreturn {85 pub fn integerOverflow() noreturn {
90 @branchHint(.cold);86 @branchHint(.cold);
...@@ -128,6 +124,10 @@ pub fn FullPanic(comptime panicFn: fn ([]const u8, ?usize) noreturn) type {...@@ -128,6 +124,10 @@ pub fn FullPanic(comptime panicFn: fn ([]const u8, ?usize) noreturn) type {
128 }124 }
129 /// Delete after next zig1.wasm update125 /// Delete after next zig1.wasm update
130 pub const memcpyLenMismatch = copyLenMismatch;126 pub const memcpyLenMismatch = copyLenMismatch;
127 /// Delete after next zig1.wasm update
128 pub const castTruncatedData = integerOutOfBounds;
129 /// Delete after next zig1.wasm update
130 pub const negativeToUnsigned = integerOutOfBounds;
131 pub fn copyLenMismatch() noreturn {131 pub fn copyLenMismatch() noreturn {
132 @branchHint(.cold);132 @branchHint(.cold);
133 call("source and destination arguments have non-equal lengths", @returnAddress());133 call("source and destination arguments have non-equal lengths", @returnAddress());
lib/std/debug/no_panic.zig+5-6
...@@ -65,12 +65,7 @@ pub fn invalidErrorCode() noreturn {...@@ -65,12 +65,7 @@ pub fn invalidErrorCode() noreturn {
65 @trap();65 @trap();
66}66}
6767
68pub fn castTruncatedData() noreturn {68pub fn integerOutOfBounds() noreturn {
69 @branchHint(.cold);
70 @trap();
71}
72
73pub fn negativeToUnsigned() noreturn {
74 @branchHint(.cold);69 @branchHint(.cold);
75 @trap();70 @trap();
76}71}
...@@ -127,6 +122,10 @@ pub fn forLenMismatch() noreturn {...@@ -127,6 +122,10 @@ pub fn forLenMismatch() noreturn {
127122
128/// Delete after next zig1.wasm update123/// Delete after next zig1.wasm update
129pub const memcpyLenMismatch = copyLenMismatch;124pub const memcpyLenMismatch = copyLenMismatch;
125/// Delete after next zig1.wasm update
126pub const castTruncatedData = integerOutOfBounds;
127/// Delete after next zig1.wasm update
128pub const negativeToUnsigned = integerOutOfBounds;
130129
131pub fn copyLenMismatch() noreturn {130pub fn copyLenMismatch() noreturn {
132 @branchHint(.cold);131 @branchHint(.cold);
lib/std/debug/simple_panic.zig+6-6
...@@ -72,12 +72,8 @@ pub fn invalidErrorCode() noreturn {...@@ -72,12 +72,8 @@ pub fn invalidErrorCode() noreturn {
72 call("invalid error code", null);72 call("invalid error code", null);
73}73}
7474
75pub fn castTruncatedData() noreturn {75pub fn integerOutOfBounds() noreturn {
76 call("integer cast truncated bits", null);76 call("integer does not fit in destination type", null);
77}
78
79pub fn negativeToUnsigned() noreturn {
80 call("attempt to cast negative value to unsigned integer", null);
81}77}
8278
83pub fn integerOverflow() noreturn {79pub fn integerOverflow() noreturn {
...@@ -122,6 +118,10 @@ pub fn forLenMismatch() noreturn {...@@ -122,6 +118,10 @@ pub fn forLenMismatch() noreturn {
122118
123/// Delete after next zig1.wasm update119/// Delete after next zig1.wasm update
124pub const memcpyLenMismatch = copyLenMismatch;120pub const memcpyLenMismatch = copyLenMismatch;
121/// Delete after next zig1.wasm update
122pub const castTruncatedData = integerOutOfBounds;
123/// Delete after next zig1.wasm update
124pub const negativeToUnsigned = integerOutOfBounds;
125125
126pub fn copyLenMismatch() noreturn {126pub fn copyLenMismatch() noreturn {
127 call("source and destination have non-equal lengths", null);127 call("source and destination have non-equal lengths", null);
src/Air/Legalize.zig+1-1
...@@ -1307,7 +1307,7 @@ fn safeIntcastBlockPayload(l: *Legalize, orig_inst: Air.Inst.Index) Error!Air.In...@@ -1307,7 +1307,7 @@ fn safeIntcastBlockPayload(l: *Legalize, orig_inst: Air.Inst.Index) Error!Air.In
1307 var main_block: Block = .init(&inst_buf);1307 var main_block: Block = .init(&inst_buf);
1308 var cur_block: *Block = &main_block;1308 var cur_block: *Block = &main_block;
13091309
1310 const panic_id: Zcu.SimplePanicId = if (dest_is_enum) .invalid_enum_value else .cast_truncated_data;1310 const panic_id: Zcu.SimplePanicId = if (dest_is_enum) .invalid_enum_value else .integer_out_of_bounds;
13111311
1312 if (have_min_check or have_max_check) {1312 if (have_min_check or have_max_check) {
1313 const dest_int_ty = if (dest_is_enum) dest_ty.intTagType(zcu) else dest_ty;1313 const dest_int_ty = if (dest_is_enum) dest_ty.intTagType(zcu) else dest_ty;
src/Sema.zig+6-10
...@@ -10263,7 +10263,7 @@ fn zirIntCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -10263,7 +10263,7 @@ fn zirIntCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
10263 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@intCast");10263 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@intCast");
10264 const operand = try sema.resolveInst(extra.rhs);10264 const operand = try sema.resolveInst(extra.rhs);
1026510265
10266 return sema.intCast(block, block.nodeOffset(inst_data.src_node), dest_ty, src, operand, operand_src, true, false);10266 return sema.intCast(block, block.nodeOffset(inst_data.src_node), dest_ty, src, operand, operand_src);
10267}10267}
1026810268
10269fn intCast(10269fn intCast(
...@@ -10274,8 +10274,6 @@ fn intCast(...@@ -10274,8 +10274,6 @@ fn intCast(
10274 dest_ty_src: LazySrcLoc,10274 dest_ty_src: LazySrcLoc,
10275 operand: Air.Inst.Ref,10275 operand: Air.Inst.Ref,
10276 operand_src: LazySrcLoc,10276 operand_src: LazySrcLoc,
10277 runtime_safety: bool,
10278 safety_panics_are_enum: bool,
10279) CompileError!Air.Inst.Ref {10277) CompileError!Air.Inst.Ref {
10280 const pt = sema.pt;10278 const pt = sema.pt;
10281 const zcu = pt.zcu;10279 const zcu = pt.zcu;
...@@ -10294,7 +10292,7 @@ fn intCast(...@@ -10294,7 +10292,7 @@ fn intCast(
1029410292
10295 if ((try sema.typeHasOnePossibleValue(dest_ty))) |opv| {10293 if ((try sema.typeHasOnePossibleValue(dest_ty))) |opv| {
10296 // requirement: intCast(u0, input) iff input == 010294 // requirement: intCast(u0, input) iff input == 0
10297 if (runtime_safety and block.wantSafety()) {10295 if (block.wantSafety()) {
10298 try sema.requireRuntimeBlock(block, src, operand_src);10296 try sema.requireRuntimeBlock(block, src, operand_src);
10299 const wanted_info = dest_scalar_ty.intInfo(zcu);10297 const wanted_info = dest_scalar_ty.intInfo(zcu);
10300 const wanted_bits = wanted_info.bits;10298 const wanted_bits = wanted_info.bits;
...@@ -10311,7 +10309,7 @@ fn intCast(...@@ -10311,7 +10309,7 @@ fn intCast(
10311 const is_in_range = try block.addBinOp(.cmp_lte, operand, zero_inst);10309 const is_in_range = try block.addBinOp(.cmp_lte, operand, zero_inst);
10312 break :ok is_in_range;10310 break :ok is_in_range;
10313 };10311 };
10314 try sema.addSafetyCheck(block, src, ok, if (safety_panics_are_enum) .invalid_enum_value else .cast_truncated_data);10312 try sema.addSafetyCheck(block, src, ok, .integer_out_of_bounds);
10315 }10313 }
10316 }10314 }
1031710315
...@@ -10319,10 +10317,9 @@ fn intCast(...@@ -10319,10 +10317,9 @@ fn intCast(
10319 }10317 }
1032010318
10321 try sema.requireRuntimeBlock(block, src, operand_src);10319 try sema.requireRuntimeBlock(block, src, operand_src);
10322 if (runtime_safety and block.wantSafety()) {10320 if (block.wantSafety()) {
10323 if (zcu.backendSupportsFeature(.panic_fn)) {10321 if (zcu.backendSupportsFeature(.panic_fn)) {
10324 _ = try sema.preparePanicId(src, .negative_to_unsigned);10322 _ = try sema.preparePanicId(src, .integer_out_of_bounds);
10325 _ = try sema.preparePanicId(src, .cast_truncated_data);
10326 }10323 }
10327 return block.addTyOp(.intcast_safe, dest_ty, operand);10324 return block.addTyOp(.intcast_safe, dest_ty, operand);
10328 }10325 }
...@@ -37984,8 +37981,7 @@ fn getExpectedBuiltinFnType(sema: *Sema, decl: Zcu.BuiltinDecl) CompileError!Typ...@@ -37984,8 +37981,7 @@ fn getExpectedBuiltinFnType(sema: *Sema, decl: Zcu.BuiltinDecl) CompileError!Typ
37984 .@"panic.castToNull",37981 .@"panic.castToNull",
37985 .@"panic.incorrectAlignment",37982 .@"panic.incorrectAlignment",
37986 .@"panic.invalidErrorCode",37983 .@"panic.invalidErrorCode",
37987 .@"panic.castTruncatedData",37984 .@"panic.integerOutOfBounds",
37988 .@"panic.negativeToUnsigned",
37989 .@"panic.integerOverflow",37985 .@"panic.integerOverflow",
37990 .@"panic.shlOverflow",37986 .@"panic.shlOverflow",
37991 .@"panic.shrOverflow",37987 .@"panic.shrOverflow",
src/Zcu.zig+4-8
...@@ -441,8 +441,7 @@ pub const BuiltinDecl = enum {...@@ -441,8 +441,7 @@ pub const BuiltinDecl = enum {
441 @"panic.castToNull",441 @"panic.castToNull",
442 @"panic.incorrectAlignment",442 @"panic.incorrectAlignment",
443 @"panic.invalidErrorCode",443 @"panic.invalidErrorCode",
444 @"panic.castTruncatedData",444 @"panic.integerOutOfBounds",
445 @"panic.negativeToUnsigned",
446 @"panic.integerOverflow",445 @"panic.integerOverflow",
447 @"panic.shlOverflow",446 @"panic.shlOverflow",
448 @"panic.shrOverflow",447 @"panic.shrOverflow",
...@@ -518,8 +517,7 @@ pub const BuiltinDecl = enum {...@@ -518,8 +517,7 @@ pub const BuiltinDecl = enum {
518 .@"panic.castToNull",517 .@"panic.castToNull",
519 .@"panic.incorrectAlignment",518 .@"panic.incorrectAlignment",
520 .@"panic.invalidErrorCode",519 .@"panic.invalidErrorCode",
521 .@"panic.castTruncatedData",520 .@"panic.integerOutOfBounds",
522 .@"panic.negativeToUnsigned",
523 .@"panic.integerOverflow",521 .@"panic.integerOverflow",
524 .@"panic.shlOverflow",522 .@"panic.shlOverflow",
525 .@"panic.shrOverflow",523 .@"panic.shrOverflow",
...@@ -585,8 +583,7 @@ pub const SimplePanicId = enum {...@@ -585,8 +583,7 @@ pub const SimplePanicId = enum {
585 cast_to_null,583 cast_to_null,
586 incorrect_alignment,584 incorrect_alignment,
587 invalid_error_code,585 invalid_error_code,
588 cast_truncated_data,586 integer_out_of_bounds,
589 negative_to_unsigned,
590 integer_overflow,587 integer_overflow,
591 shl_overflow,588 shl_overflow,
592 shr_overflow,589 shr_overflow,
...@@ -609,8 +606,7 @@ pub const SimplePanicId = enum {...@@ -609,8 +606,7 @@ pub const SimplePanicId = enum {
609 .cast_to_null => .@"panic.castToNull",606 .cast_to_null => .@"panic.castToNull",
610 .incorrect_alignment => .@"panic.incorrectAlignment",607 .incorrect_alignment => .@"panic.incorrectAlignment",
611 .invalid_error_code => .@"panic.invalidErrorCode",608 .invalid_error_code => .@"panic.invalidErrorCode",
612 .cast_truncated_data => .@"panic.castTruncatedData",609 .integer_out_of_bounds => .@"panic.integerOutOfBounds",
613 .negative_to_unsigned => .@"panic.negativeToUnsigned",
614 .integer_overflow => .@"panic.integerOverflow",610 .integer_overflow => .@"panic.integerOverflow",
615 .shl_overflow => .@"panic.shlOverflow",611 .shl_overflow => .@"panic.shlOverflow",
616 .shr_overflow => .@"panic.shrOverflow",612 .shr_overflow => .@"panic.shrOverflow",
src/codegen/llvm.zig+3-7
...@@ -9189,11 +9189,7 @@ pub const FuncGen = struct {...@@ -9189,11 +9189,7 @@ pub const FuncGen = struct {
9189 const is_vector = operand_ty.zigTypeTag(zcu) == .vector;9189 const is_vector = operand_ty.zigTypeTag(zcu) == .vector;
9190 assert(is_vector == (dest_ty.zigTypeTag(zcu) == .vector));9190 assert(is_vector == (dest_ty.zigTypeTag(zcu) == .vector));
91919191
9192 const min_panic_id: Zcu.SimplePanicId, const max_panic_id: Zcu.SimplePanicId = id: {9192 const panic_id: Zcu.SimplePanicId = if (dest_is_enum) .invalid_enum_value else .integer_out_of_bounds;
9193 if (dest_is_enum) break :id .{ .invalid_enum_value, .invalid_enum_value };
9194 if (dest_info.signedness == .unsigned) break :id .{ .negative_to_unsigned, .cast_truncated_data };
9195 break :id .{ .cast_truncated_data, .cast_truncated_data };
9196 };
91979193
9198 if (have_min_check) {9194 if (have_min_check) {
9199 const min_const_scalar = try minIntConst(&o.builder, dest_scalar, operand_scalar_llvm_ty, zcu);9195 const min_const_scalar = try minIntConst(&o.builder, dest_scalar, operand_scalar_llvm_ty, zcu);
...@@ -9207,7 +9203,7 @@ pub const FuncGen = struct {...@@ -9207,7 +9203,7 @@ pub const FuncGen = struct {
9207 const ok_block = try fg.wip.block(1, "IntMinOk");9203 const ok_block = try fg.wip.block(1, "IntMinOk");
9208 _ = try fg.wip.brCond(ok, ok_block, fail_block, .none);9204 _ = try fg.wip.brCond(ok, ok_block, fail_block, .none);
9209 fg.wip.cursor = .{ .block = fail_block };9205 fg.wip.cursor = .{ .block = fail_block };
9210 try fg.buildSimplePanic(min_panic_id);9206 try fg.buildSimplePanic(panic_id);
9211 fg.wip.cursor = .{ .block = ok_block };9207 fg.wip.cursor = .{ .block = ok_block };
9212 }9208 }
92139209
...@@ -9223,7 +9219,7 @@ pub const FuncGen = struct {...@@ -9223,7 +9219,7 @@ pub const FuncGen = struct {
9223 const ok_block = try fg.wip.block(1, "IntMaxOk");9219 const ok_block = try fg.wip.block(1, "IntMaxOk");
9224 _ = try fg.wip.brCond(ok, ok_block, fail_block, .none);9220 _ = try fg.wip.brCond(ok, ok_block, fail_block, .none);
9225 fg.wip.cursor = .{ .block = fail_block };9221 fg.wip.cursor = .{ .block = fail_block };
9226 try fg.buildSimplePanic(max_panic_id);9222 try fg.buildSimplePanic(panic_id);
9227 fg.wip.cursor = .{ .block = ok_block };9223 fg.wip.cursor = .{ .block = ok_block };
9228 }9224 }
9229 }9225 }
test/cases/compile_errors/bad_panic_call_signature.zig+1-4
...@@ -15,8 +15,7 @@ pub const panic = struct {...@@ -15,8 +15,7 @@ pub const panic = struct {
15 pub const castToNull = simple_panic.castToNull;15 pub const castToNull = simple_panic.castToNull;
16 pub const incorrectAlignment = simple_panic.incorrectAlignment;16 pub const incorrectAlignment = simple_panic.incorrectAlignment;
17 pub const invalidErrorCode = simple_panic.invalidErrorCode;17 pub const invalidErrorCode = simple_panic.invalidErrorCode;
18 pub const castTruncatedData = simple_panic.castTruncatedData;18 pub const integerOutOfBounds = simple_panic.integerOutOfBounds;
19 pub const negativeToUnsigned = simple_panic.negativeToUnsigned;
20 pub const integerOverflow = simple_panic.integerOverflow;19 pub const integerOverflow = simple_panic.integerOverflow;
21 pub const shlOverflow = simple_panic.shlOverflow;20 pub const shlOverflow = simple_panic.shlOverflow;
22 pub const shrOverflow = simple_panic.shrOverflow;21 pub const shrOverflow = simple_panic.shrOverflow;
...@@ -27,8 +26,6 @@ pub const panic = struct {...@@ -27,8 +26,6 @@ pub const panic = struct {
27 pub const shiftRhsTooBig = simple_panic.shiftRhsTooBig;26 pub const shiftRhsTooBig = simple_panic.shiftRhsTooBig;
28 pub const invalidEnumValue = simple_panic.invalidEnumValue;27 pub const invalidEnumValue = simple_panic.invalidEnumValue;
29 pub const forLenMismatch = simple_panic.forLenMismatch;28 pub const forLenMismatch = simple_panic.forLenMismatch;
30 /// Delete after next zig1.wasm update
31 pub const memcpyLenMismatch = copyLenMismatch;
32 pub const copyLenMismatch = simple_panic.copyLenMismatch;29 pub const copyLenMismatch = simple_panic.copyLenMismatch;
33 pub const memcpyAlias = simple_panic.memcpyAlias;30 pub const memcpyAlias = simple_panic.memcpyAlias;
34 pub const noreturnReturned = simple_panic.noreturnReturned;31 pub const noreturnReturned = simple_panic.noreturnReturned;
test/cases/compile_errors/bad_panic_generic_signature.zig+1-4
...@@ -11,8 +11,7 @@ pub const panic = struct {...@@ -11,8 +11,7 @@ pub const panic = struct {
11 pub const castToNull = simple_panic.castToNull;11 pub const castToNull = simple_panic.castToNull;
12 pub const incorrectAlignment = simple_panic.incorrectAlignment;12 pub const incorrectAlignment = simple_panic.incorrectAlignment;
13 pub const invalidErrorCode = simple_panic.invalidErrorCode;13 pub const invalidErrorCode = simple_panic.invalidErrorCode;
14 pub const castTruncatedData = simple_panic.castTruncatedData;14 pub const integerOutOfBounds = simple_panic.integerOutOfBounds;
15 pub const negativeToUnsigned = simple_panic.negativeToUnsigned;
16 pub const integerOverflow = simple_panic.integerOverflow;15 pub const integerOverflow = simple_panic.integerOverflow;
17 pub const shlOverflow = simple_panic.shlOverflow;16 pub const shlOverflow = simple_panic.shlOverflow;
18 pub const shrOverflow = simple_panic.shrOverflow;17 pub const shrOverflow = simple_panic.shrOverflow;
...@@ -23,8 +22,6 @@ pub const panic = struct {...@@ -23,8 +22,6 @@ pub const panic = struct {
23 pub const shiftRhsTooBig = simple_panic.shiftRhsTooBig;22 pub const shiftRhsTooBig = simple_panic.shiftRhsTooBig;
24 pub const invalidEnumValue = simple_panic.invalidEnumValue;23 pub const invalidEnumValue = simple_panic.invalidEnumValue;
25 pub const forLenMismatch = simple_panic.forLenMismatch;24 pub const forLenMismatch = simple_panic.forLenMismatch;
26 /// Delete after next zig1.wasm update
27 pub const memcpyLenMismatch = copyLenMismatch;
28 pub const copyLenMismatch = simple_panic.copyLenMismatch;25 pub const copyLenMismatch = simple_panic.copyLenMismatch;
29 pub const memcpyAlias = simple_panic.memcpyAlias;26 pub const memcpyAlias = simple_panic.memcpyAlias;
30 pub const noreturnReturned = simple_panic.noreturnReturned;27 pub const noreturnReturned = simple_panic.noreturnReturned;
test/cases/safety/@intCast to u0.zig +1-1
...@@ -2,7 +2,7 @@ const std = @import("std");...@@ -2,7 +2,7 @@ const std = @import("std");
22
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
4 _ = stack_trace;4 _ = stack_trace;
5 if (std.mem.eql(u8, message, "integer cast truncated bits")) {5 if (std.mem.eql(u8, message, "integer does not fit in destination type")) {
6 std.process.exit(0);6 std.process.exit(0);
7 }7 }
8 std.process.exit(1);8 std.process.exit(1);
test/cases/safety/signed integer not fitting in cast to unsigned integer - widening.zig +1-1
...@@ -2,7 +2,7 @@ const std = @import("std");...@@ -2,7 +2,7 @@ const std = @import("std");
22
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
4 _ = stack_trace;4 _ = stack_trace;
5 if (std.mem.eql(u8, message, "attempt to cast negative value to unsigned integer")) {5 if (std.mem.eql(u8, message, "integer does not fit in destination type")) {
6 std.process.exit(0);6 std.process.exit(0);
7 }7 }
8 std.process.exit(1);8 std.process.exit(1);
test/cases/safety/signed integer not fitting in cast to unsigned integer.zig +1-1
...@@ -2,7 +2,7 @@ const std = @import("std");...@@ -2,7 +2,7 @@ const std = @import("std");
22
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
4 _ = stack_trace;4 _ = stack_trace;
5 if (std.mem.eql(u8, message, "attempt to cast negative value to unsigned integer")) {5 if (std.mem.eql(u8, message, "integer does not fit in destination type")) {
6 std.process.exit(0);6 std.process.exit(0);
7 }7 }
8 std.process.exit(1);8 std.process.exit(1);
test/cases/safety/signed-unsigned vector cast.zig +1-1
...@@ -2,7 +2,7 @@ const std = @import("std");...@@ -2,7 +2,7 @@ const std = @import("std");
22
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
4 _ = stack_trace;4 _ = stack_trace;
5 if (std.mem.eql(u8, message, "attempt to cast negative value to unsigned integer")) {5 if (std.mem.eql(u8, message, "integer does not fit in destination type")) {
6 std.process.exit(0);6 std.process.exit(0);
7 }7 }
8 std.process.exit(1);8 std.process.exit(1);
test/cases/safety/truncating vector cast.zig +1-1
...@@ -2,7 +2,7 @@ const std = @import("std");...@@ -2,7 +2,7 @@ const std = @import("std");
22
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
4 _ = stack_trace;4 _ = stack_trace;
5 if (std.mem.eql(u8, message, "integer cast truncated bits")) {5 if (std.mem.eql(u8, message, "integer does not fit in destination type")) {
6 std.process.exit(0);6 std.process.exit(0);
7 }7 }
8 std.process.exit(1);8 std.process.exit(1);
test/cases/safety/unsigned integer not fitting in cast to signed integer - same bit count.zig +1-1
...@@ -2,7 +2,7 @@ const std = @import("std");...@@ -2,7 +2,7 @@ const std = @import("std");
22
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
4 _ = stack_trace;4 _ = stack_trace;
5 if (std.mem.eql(u8, message, "integer cast truncated bits")) {5 if (std.mem.eql(u8, message, "integer does not fit in destination type")) {
6 std.process.exit(0);6 std.process.exit(0);
7 }7 }
8 std.process.exit(1);8 std.process.exit(1);
test/cases/safety/unsigned-signed vector cast.zig +1-1
...@@ -2,7 +2,7 @@ const std = @import("std");...@@ -2,7 +2,7 @@ const std = @import("std");
22
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
4 _ = stack_trace;4 _ = stack_trace;
5 if (std.mem.eql(u8, message, "integer cast truncated bits")) {5 if (std.mem.eql(u8, message, "integer does not fit in destination type")) {
6 std.process.exit(0);6 std.process.exit(0);
7 }7 }
8 std.process.exit(1);8 std.process.exit(1);
test/cases/safety/value does not fit in shortening cast - u0.zig +1-1
...@@ -2,7 +2,7 @@ const std = @import("std");...@@ -2,7 +2,7 @@ const std = @import("std");
22
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
4 _ = stack_trace;4 _ = stack_trace;
5 if (std.mem.eql(u8, message, "integer cast truncated bits")) {5 if (std.mem.eql(u8, message, "integer does not fit in destination type")) {
6 std.process.exit(0);6 std.process.exit(0);
7 }7 }
8 std.process.exit(1);8 std.process.exit(1);
test/cases/safety/value does not fit in shortening cast.zig +1-1
...@@ -2,7 +2,7 @@ const std = @import("std");...@@ -2,7 +2,7 @@ const std = @import("std");
22
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
4 _ = stack_trace;4 _ = stack_trace;
5 if (std.mem.eql(u8, message, "integer cast truncated bits")) {5 if (std.mem.eql(u8, message, "integer does not fit in destination type")) {
6 std.process.exit(0);6 std.process.exit(0);
7 }7 }
8 std.process.exit(1);8 std.process.exit(1);
test/incremental/change_panic_handler_explicit+3-12
...@@ -26,8 +26,7 @@ pub const panic = struct {...@@ -26,8 +26,7 @@ pub const panic = struct {
26 pub const castToNull = no_panic.castToNull;26 pub const castToNull = no_panic.castToNull;
27 pub const incorrectAlignment = no_panic.incorrectAlignment;27 pub const incorrectAlignment = no_panic.incorrectAlignment;
28 pub const invalidErrorCode = no_panic.invalidErrorCode;28 pub const invalidErrorCode = no_panic.invalidErrorCode;
29 pub const castTruncatedData = no_panic.castTruncatedData;29 pub const integerOutOfBounds = no_panic.integerOutOfBounds;
30 pub const negativeToUnsigned = no_panic.negativeToUnsigned;
31 pub const shlOverflow = no_panic.shlOverflow;30 pub const shlOverflow = no_panic.shlOverflow;
32 pub const shrOverflow = no_panic.shrOverflow;31 pub const shrOverflow = no_panic.shrOverflow;
33 pub const divideByZero = no_panic.divideByZero;32 pub const divideByZero = no_panic.divideByZero;
...@@ -37,8 +36,6 @@ pub const panic = struct {...@@ -37,8 +36,6 @@ pub const panic = struct {
37 pub const shiftRhsTooBig = no_panic.shiftRhsTooBig;36 pub const shiftRhsTooBig = no_panic.shiftRhsTooBig;
38 pub const invalidEnumValue = no_panic.invalidEnumValue;37 pub const invalidEnumValue = no_panic.invalidEnumValue;
39 pub const forLenMismatch = no_panic.forLenMismatch;38 pub const forLenMismatch = no_panic.forLenMismatch;
40 /// Delete after next zig1.wasm update
41 pub const memcpyLenMismatch = copyLenMismatch;
42 pub const copyLenMismatch = no_panic.copyLenMismatch;39 pub const copyLenMismatch = no_panic.copyLenMismatch;
43 pub const memcpyAlias = no_panic.memcpyAlias;40 pub const memcpyAlias = no_panic.memcpyAlias;
44 pub const noreturnReturned = no_panic.noreturnReturned;41 pub const noreturnReturned = no_panic.noreturnReturned;
...@@ -75,8 +72,7 @@ pub const panic = struct {...@@ -75,8 +72,7 @@ pub const panic = struct {
75 pub const castToNull = no_panic.castToNull;72 pub const castToNull = no_panic.castToNull;
76 pub const incorrectAlignment = no_panic.incorrectAlignment;73 pub const incorrectAlignment = no_panic.incorrectAlignment;
77 pub const invalidErrorCode = no_panic.invalidErrorCode;74 pub const invalidErrorCode = no_panic.invalidErrorCode;
78 pub const castTruncatedData = no_panic.castTruncatedData;75 pub const integerOutOfBounds = no_panic.integerOutOfBounds;
79 pub const negativeToUnsigned = no_panic.negativeToUnsigned;
80 pub const shlOverflow = no_panic.shlOverflow;76 pub const shlOverflow = no_panic.shlOverflow;
81 pub const shrOverflow = no_panic.shrOverflow;77 pub const shrOverflow = no_panic.shrOverflow;
82 pub const divideByZero = no_panic.divideByZero;78 pub const divideByZero = no_panic.divideByZero;
...@@ -86,8 +82,6 @@ pub const panic = struct {...@@ -86,8 +82,6 @@ pub const panic = struct {
86 pub const shiftRhsTooBig = no_panic.shiftRhsTooBig;82 pub const shiftRhsTooBig = no_panic.shiftRhsTooBig;
87 pub const invalidEnumValue = no_panic.invalidEnumValue;83 pub const invalidEnumValue = no_panic.invalidEnumValue;
88 pub const forLenMismatch = no_panic.forLenMismatch;84 pub const forLenMismatch = no_panic.forLenMismatch;
89 /// Delete after next zig1.wasm update
90 pub const memcpyLenMismatch = copyLenMismatch;
91 pub const copyLenMismatch = no_panic.copyLenMismatch;85 pub const copyLenMismatch = no_panic.copyLenMismatch;
92 pub const memcpyAlias = no_panic.memcpyAlias;86 pub const memcpyAlias = no_panic.memcpyAlias;
93 pub const noreturnReturned = no_panic.noreturnReturned;87 pub const noreturnReturned = no_panic.noreturnReturned;
...@@ -124,8 +118,7 @@ pub const panic = struct {...@@ -124,8 +118,7 @@ pub const panic = struct {
124 pub const castToNull = no_panic.castToNull;118 pub const castToNull = no_panic.castToNull;
125 pub const incorrectAlignment = no_panic.incorrectAlignment;119 pub const incorrectAlignment = no_panic.incorrectAlignment;
126 pub const invalidErrorCode = no_panic.invalidErrorCode;120 pub const invalidErrorCode = no_panic.invalidErrorCode;
127 pub const castTruncatedData = no_panic.castTruncatedData;121 pub const integerOutOfBounds = no_panic.integerOutOfBounds;
128 pub const negativeToUnsigned = no_panic.negativeToUnsigned;
129 pub const shlOverflow = no_panic.shlOverflow;122 pub const shlOverflow = no_panic.shlOverflow;
130 pub const shrOverflow = no_panic.shrOverflow;123 pub const shrOverflow = no_panic.shrOverflow;
131 pub const divideByZero = no_panic.divideByZero;124 pub const divideByZero = no_panic.divideByZero;
...@@ -135,8 +128,6 @@ pub const panic = struct {...@@ -135,8 +128,6 @@ pub const panic = struct {
135 pub const shiftRhsTooBig = no_panic.shiftRhsTooBig;128 pub const shiftRhsTooBig = no_panic.shiftRhsTooBig;
136 pub const invalidEnumValue = no_panic.invalidEnumValue;129 pub const invalidEnumValue = no_panic.invalidEnumValue;
137 pub const forLenMismatch = no_panic.forLenMismatch;130 pub const forLenMismatch = no_panic.forLenMismatch;
138 /// Delete after next zig1.wasm update
139 pub const memcpyLenMismatch = copyLenMismatch;
140 pub const copyLenMismatch = no_panic.copyLenMismatch;131 pub const copyLenMismatch = no_panic.copyLenMismatch;
141 pub const memcpyAlias = no_panic.memcpyAlias;132 pub const memcpyAlias = no_panic.memcpyAlias;
142 pub const noreturnReturned = no_panic.noreturnReturned;133 pub const noreturnReturned = no_panic.noreturnReturned;