diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-09-21 02:56:21 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-21 02:56:21 -0400 |
| commit | 902f6db67b2d25f238fb13e458a12e06df62dadb (patch) | |
| tree | 5736f130758bcdc22babb60ac2ded441d43eb28e | |
| parent | 62ecc154d9ad065aee57d81afd3a478dd8360fb7 (diff) | |
| parent | d7d21672b83b64fd522a5998780bfde6ef724557 (diff) | |
| download | zig-902f6db67b2d25f238fb13e458a12e06df62dadb.tar.gz zig-902f6db67b2d25f238fb13e458a12e06df62dadb.zip | |
Merge pull request #12889 from ziglang/unwrap-error-switch
safety: show error return trace when unwrapping error in switch
95 files changed, 307 insertions, 182 deletions
diff --git a/ci/azure/pipelines.yml b/ci/azure/pipelines.yml index 0f9b447cab..d1ff725e96 100644 --- a/ci/azure/pipelines.yml +++ b/ci/azure/pipelines.yml @@ -16,7 +16,7 @@ jobs: vmImage: 'windows-2019' variables: TARGET: 'x86_64-windows-gnu' - ZIG_LLVM_CLANG_LLD_NAME: 'zig+llvm+lld+clang-${{ variables.TARGET }}-0.10.0-dev.61+9be8396b7' + ZIG_LLVM_CLANG_LLD_NAME: 'zig+llvm+lld+clang-${{ variables.TARGET }}-0.10.0-dev.4138+3f5ee6f03' ZIG_LLVM_CLANG_LLD_URL: 'https://ziglang.org/deps/${{ variables.ZIG_LLVM_CLANG_LLD_NAME }}.zip' steps: - pwsh: | @@ -58,7 +58,7 @@ comptime { // Avoid dragging in the runtime safety mechanisms into this .o file, // unless we're trying to test this file. -pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { @setCold(true); _ = error_return_trace; if (builtin.is_test) { diff --git a/lib/compiler_rt/common.zig b/lib/compiler_rt/common.zig index 0147bd423b..a34b88429f 100644 --- a/lib/compiler_rt/common.zig +++ b/lib/compiler_rt/common.zig @@ -60,7 +60,7 @@ pub const want_sparc_abi = builtin.cpu.arch.isSPARC(); // Avoid dragging in the runtime safety mechanisms into this .o file, // unless we're trying to test compiler-rt. -pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = error_return_trace; if (builtin.is_test) { @setCold(true); diff --git a/lib/ssp.zig b/lib/ssp.zig index b205a09e0a..f11698750d 100644 --- a/lib/ssp.zig +++ b/lib/ssp.zig @@ -20,7 +20,7 @@ extern fn memcpy(noalias dest: ?[*]u8, noalias src: ?[*]const u8, n: usize) call extern fn memmove(dest: ?[*]u8, src: ?[*]const u8, n: usize) callconv(.C) ?[*]u8; // Avoid dragging in the runtime safety mechanisms into this .o file. -pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = msg; _ = error_return_trace; @setCold(true); diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index d65e12988d..aff47ac6ba 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -748,7 +748,7 @@ const testFnProto = switch (builtin.zig_backend) { /// This function type is used by the Zig language code generation and /// therefore must be kept in sync with the compiler implementation. -pub const PanicFn = fn ([]const u8, ?*StackTrace) noreturn; +pub const PanicFn = fn ([]const u8, ?*StackTrace, ?usize) noreturn; /// This function is used by the Zig language code generation and /// therefore must be kept in sync with the compiler implementation. @@ -761,7 +761,7 @@ else /// This function is used by the Zig language code generation and /// therefore must be kept in sync with the compiler implementation. -pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn { +pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace, ret_addr: ?usize) noreturn { @setCold(true); // Until self-hosted catches up with stage1 language features, we have a simpler @@ -839,7 +839,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn std.os.abort(); }, else => { - const first_trace_addr = @returnAddress(); + const first_trace_addr = ret_addr orelse @returnAddress(); std.debug.panicImpl(error_return_trace, first_trace_addr, msg); }, } @@ -853,17 +853,17 @@ pub fn checkNonScalarSentinel(expected: anytype, actual: @TypeOf(expected)) void pub fn panicSentinelMismatch(expected: anytype, actual: @TypeOf(expected)) noreturn { @setCold(true); - std.debug.panic("sentinel mismatch: expected {any}, found {any}", .{ expected, actual }); + std.debug.panicExtra(null, @returnAddress(), "sentinel mismatch: expected {any}, found {any}", .{ expected, actual }); } pub fn panicUnwrapError(st: ?*StackTrace, err: anyerror) noreturn { @setCold(true); - std.debug.panicExtra(st, "attempt to unwrap error: {s}", .{@errorName(err)}); + std.debug.panicExtra(st, @returnAddress(), "attempt to unwrap error: {s}", .{@errorName(err)}); } pub fn panicOutOfBounds(index: usize, len: usize) noreturn { @setCold(true); - std.debug.panic("index out of bounds: index {d}, len {d}", .{ index, len }); + std.debug.panicExtra(null, @returnAddress(), "index out of bounds: index {d}, len {d}", .{ index, len }); } pub noinline fn returnError(st: *StackTrace) void { diff --git a/lib/std/debug.zig b/lib/std/debug.zig index a7f0b202cb..cfe646647b 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -284,13 +284,14 @@ pub fn assert(ok: bool) void { pub fn panic(comptime format: []const u8, args: anytype) noreturn { @setCold(true); - panicExtra(null, format, args); + panicExtra(null, null, format, args); } /// `panicExtra` is useful when you want to print out an `@errorReturnTrace` /// and also print out some values. pub fn panicExtra( trace: ?*std.builtin.StackTrace, + ret_addr: ?usize, comptime format: []const u8, args: anytype, ) noreturn { @@ -308,7 +309,7 @@ pub fn panicExtra( break :blk &buf; }, }; - std.builtin.panic(msg, trace); + std.builtin.panic(msg, trace, ret_addr); } /// Non-zero whenever the program triggered a panic. diff --git a/src/AstGen.zig b/src/AstGen.zig index 132525e4d4..0f04cd4b08 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -884,33 +884,6 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: Ast.Node.Index) InnerEr catch_token + 2 else null; - - var rhs = node_datas[node].rhs; - while (true) switch (node_tags[rhs]) { - .grouped_expression => rhs = node_datas[rhs].lhs, - .unreachable_literal => { - if (payload_token != null and mem.eql(u8, tree.tokenSlice(payload_token.?), "_")) { - return astgen.failTok(payload_token.?, "discard of error capture; omit it instead", .{}); - } else if (payload_token != null) { - return astgen.failTok(payload_token.?, "unused capture", .{}); - } - const lhs = node_datas[node].lhs; - - const operand = try reachableExpr(gz, scope, switch (rl) { - .ref => .ref, - else => .none, - }, lhs, lhs); - const result = try gz.addUnNode(switch (rl) { - .ref => .err_union_payload_safe_ptr, - else => .err_union_payload_safe, - }, operand, node); - switch (rl) { - .none, .coerced_ty, .discard, .ref => return result, - else => return rvalue(gz, rl, result, lhs), - } - }, - else => break, - }; switch (rl) { .ref => return orelseCatchExpr( gz, @@ -2375,9 +2348,7 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As .optional_payload_unsafe, .optional_payload_safe_ptr, .optional_payload_unsafe_ptr, - .err_union_payload_safe, .err_union_payload_unsafe, - .err_union_payload_safe_ptr, .err_union_payload_unsafe_ptr, .err_union_code, .err_union_code_ptr, diff --git a/src/Sema.zig b/src/Sema.zig index 171b349758..82593f3935 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -747,10 +747,8 @@ fn analyzeBodyInner( .int_to_enum => try sema.zirIntToEnum(block, inst), .err_union_code => try sema.zirErrUnionCode(block, inst), .err_union_code_ptr => try sema.zirErrUnionCodePtr(block, inst), - .err_union_payload_safe => try sema.zirErrUnionPayload(block, inst, true), - .err_union_payload_safe_ptr => try sema.zirErrUnionPayloadPtr(block, inst, true), - .err_union_payload_unsafe => try sema.zirErrUnionPayload(block, inst, false), - .err_union_payload_unsafe_ptr => try sema.zirErrUnionPayloadPtr(block, inst, false), + .err_union_payload_unsafe => try sema.zirErrUnionPayload(block, inst), + .err_union_payload_unsafe_ptr => try sema.zirErrUnionPayloadPtr(block, inst), .error_union_type => try sema.zirErrorUnionType(block, inst), .error_value => try sema.zirErrorValue(block, inst), .field_ptr => try sema.zirFieldPtr(block, inst, false), @@ -1355,6 +1353,8 @@ fn analyzeBodyInner( const else_body = sema.code.extra[extra.end + then_body.len ..][0..extra.data.else_body_len]; const cond = try sema.resolveInstConst(block, cond_src, extra.data.condition, "condition in comptime branch must be comptime known"); const inline_body = if (cond.val.toBool()) then_body else else_body; + + try sema.maybeErrorUnwrapCondbr(block, inline_body, extra.data.condition, cond_src); const break_data = (try sema.analyzeBodyBreak(block, inline_body)) orelse break always_noreturn; if (inst == break_data.block_inst) { @@ -1955,7 +1955,7 @@ fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError { err_msg.src_loc.file_scope.sub_file_path, err_msg.src_loc.lazy, }); - crash_report.compilerPanic("unexpected compile error occurred", null); + crash_report.compilerPanic("unexpected compile error occurred", null, null); } const mod = sema.mod; @@ -7426,7 +7426,6 @@ fn zirErrUnionPayload( sema: *Sema, block: *Block, inst: Zir.Inst.Index, - safety_check: bool, ) CompileError!Air.Inst.Ref { const tracy = trace(@src()); defer tracy.end(); @@ -7441,7 +7440,7 @@ fn zirErrUnionPayload( err_union_ty.fmt(sema.mod), }); } - return sema.analyzeErrUnionPayload(block, src, err_union_ty, operand, operand_src, safety_check); + return sema.analyzeErrUnionPayload(block, src, err_union_ty, operand, operand_src, false); } fn analyzeErrUnionPayload( @@ -7479,7 +7478,6 @@ fn zirErrUnionPayloadPtr( sema: *Sema, block: *Block, inst: Zir.Inst.Index, - safety_check: bool, ) CompileError!Air.Inst.Ref { const tracy = trace(@src()); defer tracy.end(); @@ -7488,7 +7486,7 @@ fn zirErrUnionPayloadPtr( const operand = try sema.resolveInst(inst_data.operand); const src = inst_data.src(); - return sema.analyzeErrUnionPayloadPtr(block, src, operand, safety_check, false); + return sema.analyzeErrUnionPayloadPtr(block, src, operand, false, false); } fn analyzeErrUnionPayloadPtr( @@ -9247,6 +9245,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError var empty_enum = false; const operand_ty = sema.typeOf(operand); + const err_set = operand_ty.zigTypeTag() == .ErrorSet; var else_error_ty: ?Type = null; @@ -9829,6 +9828,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError // Validation above ensured these will succeed. const item_val = sema.resolveConstValue(&child_block, .unneeded, item, undefined) catch unreachable; if (operand_val.eql(item_val, operand_ty, sema.mod)) { + if (err_set) try sema.maybeErrorUnwrapComptime(&child_block, body, operand); return sema.resolveBlockBody(block, src, &child_block, body, inst, merges); } } @@ -9851,6 +9851,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError // Validation above ensured these will succeed. const item_val = sema.resolveConstValue(&child_block, .unneeded, item, undefined) catch unreachable; if (operand_val.eql(item_val, operand_ty, sema.mod)) { + if (err_set) try sema.maybeErrorUnwrapComptime(&child_block, body, operand); return sema.resolveBlockBody(block, src, &child_block, body, inst, merges); } } @@ -9868,6 +9869,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError if ((try sema.compare(block, src, operand_val, .gte, first_tv.val, operand_ty)) and (try sema.compare(block, src, operand_val, .lte, last_tv.val, operand_ty))) { + if (err_set) try sema.maybeErrorUnwrapComptime(&child_block, body, operand); return sema.resolveBlockBody(block, src, &child_block, body, inst, merges); } } @@ -9875,6 +9877,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError extra_index += body_len; } } + if (err_set) try sema.maybeErrorUnwrapComptime(&child_block, special.body, operand); return sema.resolveBlockBody(block, src, &child_block, special.body, inst, merges); } @@ -9885,6 +9888,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError if (special_prong == .none) { return sema.fail(block, src, "switch must handle all possibilities", .{}); } + if (err_set and try sema.maybeErrorUnwrap(block, special.body, operand)) { + return Air.Inst.Ref.unreachable_value; + } return sema.resolveBlockBody(block, src, &child_block, special.body, inst, merges); } @@ -9927,7 +9933,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError break :blk field_ty.zigTypeTag() != .NoReturn; } else true; - if (analyze_body) { + if (err_set and try sema.maybeErrorUnwrap(&case_block, body, operand)) { + // nothing to do here + } else if (analyze_body) { _ = sema.analyzeBodyInner(&case_block, body) catch |err| switch (err) { error.ComptimeBreak => { const zir_datas = sema.code.instructions.items(.data); @@ -9995,7 +10003,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError const body = sema.code.extra[extra_index..][0..body_len]; extra_index += body_len; - if (analyze_body) { + if (err_set and try sema.maybeErrorUnwrap(&case_block, body, operand)) { + // nothing to do here + } else if (analyze_body) { _ = sema.analyzeBodyInner(&case_block, body) catch |err| switch (err) { error.ComptimeBreak => { const zir_datas = sema.code.instructions.items(.data); @@ -10085,18 +10095,22 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError const body = sema.code.extra[extra_index..][0..body_len]; extra_index += body_len; - _ = sema.analyzeBodyInner(&case_block, body) catch |err| switch (err) { - error.ComptimeBreak => { - const zir_datas = sema.code.instructions.items(.data); - const break_data = zir_datas[sema.comptime_break_inst].@"break"; - try sema.addRuntimeBreak(&case_block, .{ - .block_inst = break_data.block_inst, - .operand = break_data.operand, - .inst = sema.comptime_break_inst, - }); - }, - else => |e| return e, - }; + if (err_set and try sema.maybeErrorUnwrap(&case_block, body, operand)) { + // nothing to do here + } else { + _ = sema.analyzeBodyInner(&case_block, body) catch |err| switch (err) { + error.ComptimeBreak => { + const zir_datas = sema.code.instructions.items(.data); + const break_data = zir_datas[sema.comptime_break_inst].@"break"; + try sema.addRuntimeBreak(&case_block, .{ + .block_inst = break_data.block_inst, + .operand = break_data.operand, + .inst = sema.comptime_break_inst, + }); + }, + else => |e| return e, + }; + } try wip_captures.finalize(); @@ -10141,8 +10155,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError } else false else true; - - if (special.body.len != 0 and analyze_body) { + if (special.body.len != 0 and err_set and + try sema.maybeErrorUnwrap(&case_block, special.body, operand)) + { + // nothing to do here + } else if (special.body.len != 0 and analyze_body) { _ = sema.analyzeBodyInner(&case_block, special.body) catch |err| switch (err) { error.ComptimeBreak => { const zir_datas = sema.code.instructions.items(.data); @@ -10400,6 +10417,109 @@ fn validateSwitchNoRange( return sema.failWithOwnedErrorMsg(msg); } +fn maybeErrorUnwrap(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, operand: Air.Inst.Ref) !bool { + const this_feature_is_implemented_in_the_backend = + sema.mod.comp.bin_file.options.use_llvm; + + if (!this_feature_is_implemented_in_the_backend) return false; + + const tags = sema.code.instructions.items(.tag); + for (body) |inst| { + switch (tags[inst]) { + .dbg_block_begin, + .dbg_block_end, + .dbg_stmt, + .@"unreachable", + .str, + .as_node, + .panic, + .field_val, + => {}, + else => return false, + } + } + + for (body) |inst| { + const air_inst = switch (tags[inst]) { + .dbg_block_begin, + .dbg_block_end, + => continue, + .dbg_stmt => { + try sema.zirDbgStmt(block, inst); + continue; + }, + .str => try sema.zirStr(block, inst), + .as_node => try sema.zirAsNode(block, inst), + .field_val => try sema.zirFieldVal(block, inst), + .@"unreachable" => { + const inst_data = sema.code.instructions.items(.data)[inst].@"unreachable"; + const src = inst_data.src(); + + const panic_fn = try sema.getBuiltin(block, src, "panicUnwrapError"); + const err_return_trace = try sema.getErrorReturnTrace(block, src); + const args: [2]Air.Inst.Ref = .{ err_return_trace, operand }; + _ = try sema.analyzeCall(block, panic_fn, src, src, .auto, false, &args, null); + return true; + }, + .panic => { + const inst_data = sema.code.instructions.items(.data)[inst].un_node; + const src = inst_data.src(); + const msg_inst = try sema.resolveInst(inst_data.operand); + + const panic_fn = try sema.getBuiltin(block, src, "panic"); + const err_return_trace = try sema.getErrorReturnTrace(block, src); + const args: [3]Air.Inst.Ref = .{ msg_inst, err_return_trace, .null_value }; + _ = try sema.analyzeCall(block, panic_fn, src, src, .auto, false, &args, null); + return true; + }, + else => unreachable, + }; + if (sema.typeOf(air_inst).isNoReturn()) + return true; + try sema.inst_map.put(sema.gpa, inst, air_inst); + } + unreachable; +} + +fn maybeErrorUnwrapCondbr(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, cond: Zir.Inst.Ref, cond_src: LazySrcLoc) !void { + const index = Zir.refToIndex(cond) orelse return; + if (sema.code.instructions.items(.tag)[index] != .is_non_err) return; + + const err_inst_data = sema.code.instructions.items(.data)[index].un_node; + const err_operand = try sema.resolveInst(err_inst_data.operand); + const operand_ty = sema.typeOf(err_operand); + if (operand_ty.zigTypeTag() == .ErrorSet) { + try sema.maybeErrorUnwrapComptime(block, body, err_operand); + return; + } + if (try sema.resolveDefinedValue(block, cond_src, err_operand)) |val| { + if (val.getError() == null) return; + try sema.maybeErrorUnwrapComptime(block, body, err_operand); + } +} + +fn maybeErrorUnwrapComptime(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, operand: Air.Inst.Ref) !void { + const tags = sema.code.instructions.items(.tag); + const inst = for (body) |inst| { + switch (tags[inst]) { + .dbg_block_begin, + .dbg_block_end, + .dbg_stmt, + => {}, + .@"unreachable" => break inst, + else => return, + } + } else return; + const inst_data = sema.code.instructions.items(.data)[inst].@"unreachable"; + const src = inst_data.src(); + + if (try sema.resolveDefinedValue(block, src, operand)) |val| { + if (val.getError()) |name| { + return sema.fail(block, src, "caught unexpected error '{s}'", .{name}); + } + } +} + fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { const inst_data = sema.code.instructions.items(.data)[inst].pl_node; const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; @@ -15152,6 +15272,8 @@ fn zirCondbr( if (try sema.resolveDefinedValue(parent_block, cond_src, cond)) |cond_val| { const body = if (cond_val.toBool()) then_body else else_body; + + try sema.maybeErrorUnwrapCondbr(parent_block, body, extra.data.condition, cond_src); // We use `analyzeBodyInner` since we want to propagate any possible // `error.ComptimeBreak` to the caller. return sema.analyzeBodyInner(parent_block, body); @@ -15182,18 +15304,34 @@ fn zirCondbr( const true_instructions = sub_block.instructions.toOwnedSlice(gpa); defer gpa.free(true_instructions); - _ = sema.analyzeBodyInner(&sub_block, else_body) catch |err| switch (err) { - error.ComptimeBreak => { - const zir_datas = sema.code.instructions.items(.data); - const break_data = zir_datas[sema.comptime_break_inst].@"break"; - try sema.addRuntimeBreak(&sub_block, .{ - .block_inst = break_data.block_inst, - .operand = break_data.operand, - .inst = sema.comptime_break_inst, - }); - }, - else => |e| return e, + const err_cond = blk: { + const index = Zir.refToIndex(extra.data.condition) orelse break :blk null; + if (sema.code.instructions.items(.tag)[index] != .is_non_err) break :blk null; + + const err_inst_data = sema.code.instructions.items(.data)[index].un_node; + const err_operand = try sema.resolveInst(err_inst_data.operand); + const operand_ty = sema.typeOf(err_operand); + assert(operand_ty.zigTypeTag() == .ErrorUnion); + const result_ty = operand_ty.errorUnionSet(); + break :blk try sub_block.addTyOp(.unwrap_errunion_err, result_ty, err_operand); }; + + if (err_cond != null and try sema.maybeErrorUnwrap(&sub_block, else_body, err_cond.?)) { + // nothing to do + } else { + _ = sema.analyzeBodyInner(&sub_block, else_body) catch |err| switch (err) { + error.ComptimeBreak => { + const zir_datas = sema.code.instructions.items(.data); + const break_data = zir_datas[sema.comptime_break_inst].@"break"; + try sema.addRuntimeBreak(&sub_block, .{ + .block_inst = break_data.block_inst, + .operand = break_data.operand, + .inst = sema.comptime_break_inst, + }); + }, + else => |e| return e, + }; + } try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.CondBr).Struct.fields.len + true_instructions.len + sub_block.instructions.items.len); _ = try parent_block.addInst(.{ @@ -21001,7 +21139,7 @@ fn panicWithMsg( try Type.optional(arena, ptr_stack_trace_ty), Value.@"null", ); - const args: [2]Air.Inst.Ref = .{ msg_inst, null_stack_trace }; + const args: [3]Air.Inst.Ref = .{ msg_inst, null_stack_trace, .null_value }; _ = try sema.analyzeCall(block, panic_fn, src, src, .auto, false, &args, null); return always_noreturn; } diff --git a/src/Zir.zig b/src/Zir.zig index 4953e575f9..9fa0f42e41 100644 --- a/src/Zir.zig +++ b/src/Zir.zig @@ -629,20 +629,10 @@ pub const Inst = struct { /// No safety checks. /// Uses the `un_node` field. optional_payload_unsafe_ptr, - /// E!T => T with safety. - /// Given an error union value, returns the payload value, with a safety check - /// that the value is not an error. Used for catch, if, and while. - /// Uses the `un_node` field. - err_union_payload_safe, /// E!T => T without safety. /// Given an error union value, returns the payload value. No safety checks. /// Uses the `un_node` field. err_union_payload_unsafe, - /// *E!T => *T with safety. - /// Given a pointer to an error union value, returns a pointer to the payload value, - /// with a safety check that the value is not an error. Used for catch, if, and while. - /// Uses the `un_node` field. - err_union_payload_safe_ptr, /// *E!T => *T without safety. /// Given a pointer to a error union value, returns a pointer to the payload value. /// No safety checks. @@ -1120,9 +1110,7 @@ pub const Inst = struct { .optional_payload_unsafe, .optional_payload_safe_ptr, .optional_payload_unsafe_ptr, - .err_union_payload_safe, .err_union_payload_unsafe, - .err_union_payload_safe_ptr, .err_union_payload_unsafe_ptr, .err_union_code, .err_union_code_ptr, @@ -1421,9 +1409,7 @@ pub const Inst = struct { .optional_payload_unsafe, .optional_payload_safe_ptr, .optional_payload_unsafe_ptr, - .err_union_payload_safe, .err_union_payload_unsafe, - .err_union_payload_safe_ptr, .err_union_payload_unsafe_ptr, .err_union_code, .err_union_code_ptr, @@ -1692,9 +1678,7 @@ pub const Inst = struct { .optional_payload_unsafe = .un_node, .optional_payload_safe_ptr = .un_node, .optional_payload_unsafe_ptr = .un_node, - .err_union_payload_safe = .un_node, .err_union_payload_unsafe = .un_node, - .err_union_payload_safe_ptr = .un_node, .err_union_payload_unsafe_ptr = .un_node, .err_union_code = .un_node, .err_union_code_ptr = .un_node, diff --git a/src/crash_report.zig b/src/crash_report.zig index d38f436aa0..04fbabca09 100644 --- a/src/crash_report.zig +++ b/src/crash_report.zig @@ -155,10 +155,10 @@ fn writeFullyQualifiedDeclWithFile(mod: *Module, decl: *Decl, stream: anytype) ! try decl.renderFullyQualifiedDebugName(mod, stream); } -pub fn compilerPanic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace) noreturn { +pub fn compilerPanic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, maybe_ret_addr: ?usize) noreturn { PanicSwitch.preDispatch(); @setCold(true); - const ret_addr = @returnAddress(); + const ret_addr = maybe_ret_addr orelse @returnAddress(); const stack_ctx: StackContext = .{ .current = .{ .ret_addr = ret_addr } }; PanicSwitch.dispatch(error_return_trace, stack_ctx, msg); } diff --git a/src/print_zir.zig b/src/print_zir.zig index 9e8a3f1481..e2081172e6 100644 --- a/src/print_zir.zig +++ b/src/print_zir.zig @@ -170,9 +170,7 @@ const Writer = struct { .optional_payload_unsafe, .optional_payload_safe_ptr, .optional_payload_unsafe_ptr, - .err_union_payload_safe, .err_union_payload_unsafe, - .err_union_payload_safe_ptr, .err_union_payload_unsafe_ptr, .err_union_code, .err_union_code_ptr, diff --git a/src/stage1/codegen.cpp b/src/stage1/codegen.cpp index 55aa73a3b7..2341ad4483 100644 --- a/src/stage1/codegen.cpp +++ b/src/stage1/codegen.cpp @@ -1086,11 +1086,23 @@ static void gen_panic(CodeGen *g, LLVMValueRef msg_arg, LLVMValueRef stack_trace if (stack_trace_arg == nullptr) { stack_trace_arg = LLVMConstNull(get_llvm_type(g, ptr_to_stack_trace_type(g))); } + LLVMValueRef null_ret_alloc; + { + ZigValue null_val = {}; + null_val.special = ConstValSpecialStatic; + null_val.data.x_optional = nullptr; + null_val.type = get_optional_type2(g, g->builtin_types.entry_usize); + LLVMValueRef null_ret_val = gen_const_val(g, &null_val, ""); + null_ret_alloc = build_alloca(g, null_val.type, "ret_addr", 0); + LLVMBuildStore(g->builder, null_ret_val, null_ret_alloc); + } + LLVMValueRef args[] = { msg_arg, stack_trace_arg, + null_ret_alloc, }; - ZigLLVMBuildCall(g->builder, LLVMGlobalGetValueType(fn_val), fn_val, args, 2, llvm_cc, ZigLLVM_CallAttrAuto, ""); + ZigLLVMBuildCall(g->builder, LLVMGlobalGetValueType(fn_val), fn_val, args, 3, llvm_cc, ZigLLVM_CallAttrAuto, ""); if (!stack_trace_is_llvm_alloca) { // The stack trace argument is not in the stack of the caller, so // we'd like to set tail call here, but because slices (the type of msg_arg) are diff --git a/test/cases/compile_errors/stage1/obj/wrong_panic_signature_generic_function.zig b/test/cases/compile_errors/stage1/obj/wrong_panic_signature_generic_function.zig index 45de2fc6cb..37af5e5fce 100644 --- a/test/cases/compile_errors/stage1/obj/wrong_panic_signature_generic_function.zig +++ b/test/cases/compile_errors/stage1/obj/wrong_panic_signature_generic_function.zig @@ -1,4 +1,4 @@ -pub fn panic(comptime msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn { +pub fn panic(comptime msg: []const u8, error_return_trace: ?*builtin.StackTrace, _: ?usize) noreturn { _ = msg; _ = error_return_trace; while (true) {} } @@ -8,5 +8,5 @@ const builtin = @import("std").builtin; // backend=stage1 // target=native // -// error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn([]const u8,anytype) anytype' +// error: expected type 'fn([]const u8, ?*std.builtin.StackTrace, ?usize) noreturn', found 'fn([]const u8,anytype,anytype) anytype' // note: only one of the functions is generic diff --git a/test/cases/compile_errors/stage1/obj/wrong_panic_signature_runtime_function.zig b/test/cases/compile_errors/stage1/obj/wrong_panic_signature_runtime_function.zig index 049becaeb1..3848a5bf0c 100644 --- a/test/cases/compile_errors/stage1/obj/wrong_panic_signature_runtime_function.zig +++ b/test/cases/compile_errors/stage1/obj/wrong_panic_signature_runtime_function.zig @@ -7,4 +7,4 @@ pub fn panic() void {} // backend=stage1 // target=native // -// error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn() void' +// error: expected type 'fn([]const u8, ?*std.builtin.StackTrace, ?usize) noreturn', found 'fn() void' diff --git a/test/cases/safety/@alignCast misaligned.zig b/test/cases/safety/@alignCast misaligned.zig index e9530e83fe..aed805cf66 100644 --- a/test/cases/safety/@alignCast misaligned.zig +++ b/test/cases/safety/@alignCast misaligned.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "incorrect alignment")) { std.process.exit(0); diff --git a/test/cases/safety/@asyncCall with too small a frame.zig b/test/cases/safety/@asyncCall with too small a frame.zig index e245e9bb47..1a31593058 100644 --- a/test/cases/safety/@asyncCall with too small a frame.zig +++ b/test/cases/safety/@asyncCall with too small a frame.zig @@ -1,7 +1,7 @@ const std = @import("std"); const builtin = @import("builtin"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = message; _ = stack_trace; std.process.exit(0); diff --git a/test/cases/safety/@errSetCast error not present in destination.zig b/test/cases/safety/@errSetCast error not present in destination.zig index bf4dee8421..2fd0a912e6 100644 --- a/test/cases/safety/@errSetCast error not present in destination.zig +++ b/test/cases/safety/@errSetCast error not present in destination.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "invalid error code")) { std.process.exit(0); diff --git a/test/cases/safety/@floatToInt cannot fit - negative out of range.zig b/test/cases/safety/@floatToInt cannot fit - negative out of range.zig index 937e77a173..fa7e628f4a 100644 --- a/test/cases/safety/@floatToInt cannot fit - negative out of range.zig +++ b/test/cases/safety/@floatToInt cannot fit - negative out of range.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "integer part of floating point value out of bounds")) { std.process.exit(0); diff --git a/test/cases/safety/@floatToInt cannot fit - negative to unsigned.zig b/test/cases/safety/@floatToInt cannot fit - negative to unsigned.zig index 65da9b2da5..5bab7710b1 100644 --- a/test/cases/safety/@floatToInt cannot fit - negative to unsigned.zig +++ b/test/cases/safety/@floatToInt cannot fit - negative to unsigned.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "integer part of floating point value out of bounds")) { std.process.exit(0); diff --git a/test/cases/safety/@floatToInt cannot fit - positive out of range.zig b/test/cases/safety/@floatToInt cannot fit - positive out of range.zig index e7abf0cf63..fe931e8751 100644 --- a/test/cases/safety/@floatToInt cannot fit - positive out of range.zig +++ b/test/cases/safety/@floatToInt cannot fit - positive out of range.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "integer part of floating point value out of bounds")) { std.process.exit(0); diff --git a/test/cases/safety/@intCast to u0.zig b/test/cases/safety/@intCast to u0.zig index 0f38d59e50..f3f969548b 100644 --- a/test/cases/safety/@intCast to u0.zig +++ b/test/cases/safety/@intCast to u0.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "integer cast truncated bits")) { std.process.exit(0); diff --git a/test/cases/safety/@intToEnum - no matching tag value.zig b/test/cases/safety/@intToEnum - no matching tag value.zig index 0e5f401f6d..c4967b413b 100644 --- a/test/cases/safety/@intToEnum - no matching tag value.zig +++ b/test/cases/safety/@intToEnum - no matching tag value.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "invalid enum value")) { std.process.exit(0); diff --git a/test/cases/safety/@intToPtr address zero to non-optional byte-aligned pointer.zig b/test/cases/safety/@intToPtr address zero to non-optional byte-aligned pointer.zig index a3b7f374ce..413959706f 100644 --- a/test/cases/safety/@intToPtr address zero to non-optional byte-aligned pointer.zig +++ b/test/cases/safety/@intToPtr address zero to non-optional byte-aligned pointer.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "cast causes pointer to be null")) { std.process.exit(0); diff --git a/test/cases/safety/@intToPtr address zero to non-optional pointer.zig b/test/cases/safety/@intToPtr address zero to non-optional pointer.zig index 8724e98131..457b2d12c0 100644 --- a/test/cases/safety/@intToPtr address zero to non-optional pointer.zig +++ b/test/cases/safety/@intToPtr address zero to non-optional pointer.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "cast causes pointer to be null")) { std.process.exit(0); diff --git a/test/cases/safety/@tagName on corrupted enum value.zig b/test/cases/safety/@tagName on corrupted enum value.zig index 4081d171c4..344b75effe 100644 --- a/test/cases/safety/@tagName on corrupted enum value.zig +++ b/test/cases/safety/@tagName on corrupted enum value.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "invalid enum value")) { std.process.exit(0); diff --git a/test/cases/safety/@tagName on corrupted union value.zig b/test/cases/safety/@tagName on corrupted union value.zig index eb36fab262..f7ffb07871 100644 --- a/test/cases/safety/@tagName on corrupted union value.zig +++ b/test/cases/safety/@tagName on corrupted union value.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "invalid enum value")) { std.process.exit(0); diff --git a/test/cases/safety/array slice sentinel mismatch non-scalar.zig b/test/cases/safety/array slice sentinel mismatch non-scalar.zig index e773b165e8..6ea136bc01 100644 --- a/test/cases/safety/array slice sentinel mismatch non-scalar.zig +++ b/test/cases/safety/array slice sentinel mismatch non-scalar.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "sentinel mismatch: expected tmp.main.S{ .a = 1 }, found tmp.main.S{ .a = 2 }")) { std.process.exit(0); diff --git a/test/cases/safety/array slice sentinel mismatch vector.zig b/test/cases/safety/array slice sentinel mismatch vector.zig index 38d020d84a..da20d98869 100644 --- a/test/cases/safety/array slice sentinel mismatch vector.zig +++ b/test/cases/safety/array slice sentinel mismatch vector.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "sentinel mismatch: expected { 0, 0 }, found { 4, 4 }")) { std.process.exit(0); diff --git a/test/cases/safety/array slice sentinel mismatch.zig b/test/cases/safety/array slice sentinel mismatch.zig index 8f54b4cc53..fc19618673 100644 --- a/test/cases/safety/array slice sentinel mismatch.zig +++ b/test/cases/safety/array slice sentinel mismatch.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "sentinel mismatch: expected 0, found 4")) { std.process.exit(0); diff --git a/test/cases/safety/awaiting twice.zig b/test/cases/safety/awaiting twice.zig index 867263de6e..6767ad4e76 100644 --- a/test/cases/safety/awaiting twice.zig +++ b/test/cases/safety/awaiting twice.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = message; _ = stack_trace; std.process.exit(0); diff --git a/test/cases/safety/bad union field access.zig b/test/cases/safety/bad union field access.zig index bdde8d9f3a..0badf380fb 100644 --- a/test/cases/safety/bad union field access.zig +++ b/test/cases/safety/bad union field access.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "access of inactive union field")) { std.process.exit(0); diff --git a/test/cases/safety/calling panic.zig b/test/cases/safety/calling panic.zig index 29f3a6c663..832bc5f19a 100644 --- a/test/cases/safety/calling panic.zig +++ b/test/cases/safety/calling panic.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "oh no")) { std.process.exit(0); diff --git a/test/cases/safety/cast []u8 to bigger slice of wrong size.zig b/test/cases/safety/cast []u8 to bigger slice of wrong size.zig index 6fddb63bee..93d18178a8 100644 --- a/test/cases/safety/cast []u8 to bigger slice of wrong size.zig +++ b/test/cases/safety/cast []u8 to bigger slice of wrong size.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "exact division produced remainder")) { std.process.exit(0); diff --git a/test/cases/safety/cast integer to global error and no code matches.zig b/test/cases/safety/cast integer to global error and no code matches.zig index d423704039..466bf8d2ca 100644 --- a/test/cases/safety/cast integer to global error and no code matches.zig +++ b/test/cases/safety/cast integer to global error and no code matches.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "invalid error code")) { std.process.exit(0); diff --git a/test/cases/safety/empty slice with sentinel out of bounds.zig b/test/cases/safety/empty slice with sentinel out of bounds.zig index d989a33541..69201fde30 100644 --- a/test/cases/safety/empty slice with sentinel out of bounds.zig +++ b/test/cases/safety/empty slice with sentinel out of bounds.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "index out of bounds: index 1, len 0")) { std.process.exit(0); diff --git a/test/cases/safety/error return trace across suspend points.zig b/test/cases/safety/error return trace across suspend points.zig index b8cb90505a..28c53cb6d1 100644 --- a/test/cases/safety/error return trace across suspend points.zig +++ b/test/cases/safety/error return trace across suspend points.zig @@ -1,7 +1,7 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = message; _ = stack_trace; std.process.exit(0); diff --git a/test/cases/safety/exact division failure - vectors.zig b/test/cases/safety/exact division failure - vectors.zig index 9b792b33cf..3c515cbdf1 100644 --- a/test/cases/safety/exact division failure - vectors.zig +++ b/test/cases/safety/exact division failure - vectors.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "exact division produced remainder")) { std.process.exit(0); diff --git a/test/cases/safety/exact division failure.zig b/test/cases/safety/exact division failure.zig index ea4d39ed22..cdf1b1fb8d 100644 --- a/test/cases/safety/exact division failure.zig +++ b/test/cases/safety/exact division failure.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "exact division produced remainder")) { std.process.exit(0); diff --git a/test/cases/safety/intToPtr with misaligned address.zig b/test/cases/safety/intToPtr with misaligned address.zig index 6cb085a64b..e53c7e9087 100644 --- a/test/cases/safety/intToPtr with misaligned address.zig +++ b/test/cases/safety/intToPtr with misaligned address.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "incorrect alignment")) { std.process.exit(0); diff --git a/test/cases/safety/integer addition overflow.zig b/test/cases/safety/integer addition overflow.zig index aa2ab60dd4..4f7c5b2cb3 100644 --- a/test/cases/safety/integer addition overflow.zig +++ b/test/cases/safety/integer addition overflow.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "integer overflow")) { std.process.exit(0); diff --git a/test/cases/safety/integer division by zero - vectors.zig b/test/cases/safety/integer division by zero - vectors.zig index 0789f7f088..ed7ac7777b 100644 --- a/test/cases/safety/integer division by zero - vectors.zig +++ b/test/cases/safety/integer division by zero - vectors.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "division by zero")) { std.process.exit(0); diff --git a/test/cases/safety/integer division by zero.zig b/test/cases/safety/integer division by zero.zig index 46f57c1117..0d1b79d26d 100644 --- a/test/cases/safety/integer division by zero.zig +++ b/test/cases/safety/integer division by zero.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "division by zero")) { std.process.exit(0); diff --git a/test/cases/safety/integer multiplication overflow.zig b/test/cases/safety/integer multiplication overflow.zig index af7e638381..641801277d 100644 --- a/test/cases/safety/integer multiplication overflow.zig +++ b/test/cases/safety/integer multiplication overflow.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "integer overflow")) { std.process.exit(0); diff --git a/test/cases/safety/integer negation overflow.zig b/test/cases/safety/integer negation overflow.zig index e48ffff761..3d4c134c4a 100644 --- a/test/cases/safety/integer negation overflow.zig +++ b/test/cases/safety/integer negation overflow.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "integer overflow")) { std.process.exit(0); diff --git a/test/cases/safety/integer subtraction overflow.zig b/test/cases/safety/integer subtraction overflow.zig index 6d9380ee26..84a16f55b8 100644 --- a/test/cases/safety/integer subtraction overflow.zig +++ b/test/cases/safety/integer subtraction overflow.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "integer overflow")) { std.process.exit(0); diff --git a/test/cases/safety/invalid resume of async function.zig b/test/cases/safety/invalid resume of async function.zig index 2ed5704c74..c58f13b99d 100644 --- a/test/cases/safety/invalid resume of async function.zig +++ b/test/cases/safety/invalid resume of async function.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = message; _ = stack_trace; std.process.exit(0); diff --git a/test/cases/safety/modrem by zero.zig b/test/cases/safety/modrem by zero.zig index 435570f2fb..f201062c0e 100644 --- a/test/cases/safety/modrem by zero.zig +++ b/test/cases/safety/modrem by zero.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "division by zero")) { std.process.exit(0); diff --git a/test/cases/safety/modulus by zero.zig b/test/cases/safety/modulus by zero.zig index 9d57865a87..6714458979 100644 --- a/test/cases/safety/modulus by zero.zig +++ b/test/cases/safety/modulus by zero.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "division by zero")) { std.process.exit(0); diff --git a/test/cases/safety/nosuspend function call, callee suspends.zig b/test/cases/safety/nosuspend function call, callee suspends.zig index 42daa4a9bd..50f457f314 100644 --- a/test/cases/safety/nosuspend function call, callee suspends.zig +++ b/test/cases/safety/nosuspend function call, callee suspends.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = message; _ = stack_trace; std.process.exit(0); diff --git a/test/cases/safety/optional unwrap operator on C pointer.zig b/test/cases/safety/optional unwrap operator on C pointer.zig index 10e605cadd..a435219233 100644 --- a/test/cases/safety/optional unwrap operator on C pointer.zig +++ b/test/cases/safety/optional unwrap operator on C pointer.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "attempt to use null value")) { std.process.exit(0); diff --git a/test/cases/safety/optional unwrap operator on null pointer.zig b/test/cases/safety/optional unwrap operator on null pointer.zig index 3d2991d9ec..5749be9e36 100644 --- a/test/cases/safety/optional unwrap operator on null pointer.zig +++ b/test/cases/safety/optional unwrap operator on null pointer.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "attempt to use null value")) { std.process.exit(0); diff --git a/test/cases/safety/out of bounds slice access.zig b/test/cases/safety/out of bounds slice access.zig index ddd9e74cf2..b4c87948a5 100644 --- a/test/cases/safety/out of bounds slice access.zig +++ b/test/cases/safety/out of bounds slice access.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "index out of bounds: index 4, len 4")) { std.process.exit(0); diff --git a/test/cases/safety/pointer casting null to non-optional pointer.zig b/test/cases/safety/pointer casting null to non-optional pointer.zig index e46b84f783..6ec47f52fb 100644 --- a/test/cases/safety/pointer casting null to non-optional pointer.zig +++ b/test/cases/safety/pointer casting null to non-optional pointer.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "cast causes pointer to be null")) { std.process.exit(0); diff --git a/test/cases/safety/pointer slice sentinel mismatch.zig b/test/cases/safety/pointer slice sentinel mismatch.zig index ec25ec2969..3972528edf 100644 --- a/test/cases/safety/pointer slice sentinel mismatch.zig +++ b/test/cases/safety/pointer slice sentinel mismatch.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "sentinel mismatch: expected 0, found 4")) { std.process.exit(0); diff --git a/test/cases/safety/remainder division by zero.zig b/test/cases/safety/remainder division by zero.zig index 71e295c4dd..3dc97f6e16 100644 --- a/test/cases/safety/remainder division by zero.zig +++ b/test/cases/safety/remainder division by zero.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "division by zero")) { std.process.exit(0); diff --git a/test/cases/safety/resuming a function which is awaiting a call.zig b/test/cases/safety/resuming a function which is awaiting a call.zig index b344441507..47545584ea 100644 --- a/test/cases/safety/resuming a function which is awaiting a call.zig +++ b/test/cases/safety/resuming a function which is awaiting a call.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = message; _ = stack_trace; std.process.exit(0); diff --git a/test/cases/safety/resuming a function which is awaiting a frame.zig b/test/cases/safety/resuming a function which is awaiting a frame.zig index e63b49183e..26df1ae900 100644 --- a/test/cases/safety/resuming a function which is awaiting a frame.zig +++ b/test/cases/safety/resuming a function which is awaiting a frame.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = message; _ = stack_trace; std.process.exit(0); diff --git a/test/cases/safety/resuming a non-suspended function which has been suspended and resumed.zig b/test/cases/safety/resuming a non-suspended function which has been suspended and resumed.zig index 54de0b9ebd..e03974f08d 100644 --- a/test/cases/safety/resuming a non-suspended function which has been suspended and resumed.zig +++ b/test/cases/safety/resuming a non-suspended function which has been suspended and resumed.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = message; _ = stack_trace; std.process.exit(0); diff --git a/test/cases/safety/resuming a non-suspended function which never been suspended.zig b/test/cases/safety/resuming a non-suspended function which never been suspended.zig index 8c35753d6d..fb3f5aa307 100644 --- a/test/cases/safety/resuming a non-suspended function which never been suspended.zig +++ b/test/cases/safety/resuming a non-suspended function which never been suspended.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = message; _ = stack_trace; std.process.exit(0); diff --git a/test/cases/safety/shift left by huge amount.zig b/test/cases/safety/shift left by huge amount.zig index e786a739d6..d89f7d4ebe 100644 --- a/test/cases/safety/shift left by huge amount.zig +++ b/test/cases/safety/shift left by huge amount.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "shift amount is greater than the type size")) { std.process.exit(0); diff --git a/test/cases/safety/shift right by huge amount.zig b/test/cases/safety/shift right by huge amount.zig index a45b8c24ce..8107bc1738 100644 --- a/test/cases/safety/shift right by huge amount.zig +++ b/test/cases/safety/shift right by huge amount.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "shift amount is greater than the type size")) { std.process.exit(0); diff --git a/test/cases/safety/signed integer division overflow - vectors.zig b/test/cases/safety/signed integer division overflow - vectors.zig index 8bc5be0d63..53e72e90fe 100644 --- a/test/cases/safety/signed integer division overflow - vectors.zig +++ b/test/cases/safety/signed integer division overflow - vectors.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "integer overflow")) { std.process.exit(0); diff --git a/test/cases/safety/signed integer division overflow.zig b/test/cases/safety/signed integer division overflow.zig index 6d17c284df..9d1014ceec 100644 --- a/test/cases/safety/signed integer division overflow.zig +++ b/test/cases/safety/signed integer division overflow.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "integer overflow")) { std.process.exit(0); diff --git a/test/cases/safety/signed integer not fitting in cast to unsigned integer - widening.zig b/test/cases/safety/signed integer not fitting in cast to unsigned integer - widening.zig index 6ee23c9aee..a79298b7da 100644 --- a/test/cases/safety/signed integer not fitting in cast to unsigned integer - widening.zig +++ b/test/cases/safety/signed integer not fitting in cast to unsigned integer - widening.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "attempt to cast negative value to unsigned integer")) { std.process.exit(0); diff --git a/test/cases/safety/signed integer not fitting in cast to unsigned integer.zig b/test/cases/safety/signed integer not fitting in cast to unsigned integer.zig index 5c21e0a098..6c4e9e256d 100644 --- a/test/cases/safety/signed integer not fitting in cast to unsigned integer.zig +++ b/test/cases/safety/signed integer not fitting in cast to unsigned integer.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "attempt to cast negative value to unsigned integer")) { std.process.exit(0); diff --git a/test/cases/safety/signed shift left overflow.zig b/test/cases/safety/signed shift left overflow.zig index 75e9711032..f9a4db81ce 100644 --- a/test/cases/safety/signed shift left overflow.zig +++ b/test/cases/safety/signed shift left overflow.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "left shift overflowed bits")) { std.process.exit(0); diff --git a/test/cases/safety/signed shift right overflow.zig b/test/cases/safety/signed shift right overflow.zig index 52c6158a4d..7d71b9ffbd 100644 --- a/test/cases/safety/signed shift right overflow.zig +++ b/test/cases/safety/signed shift right overflow.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "right shift overflowed bits")) { std.process.exit(0); diff --git a/test/cases/safety/signed-unsigned vector cast.zig b/test/cases/safety/signed-unsigned vector cast.zig index 5d8a2ea271..d287c0a1ae 100644 --- a/test/cases/safety/signed-unsigned vector cast.zig +++ b/test/cases/safety/signed-unsigned vector cast.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "attempt to cast negative value to unsigned integer")) { std.process.exit(0); diff --git a/test/cases/safety/slice sentinel mismatch - floats.zig b/test/cases/safety/slice sentinel mismatch - floats.zig index 3d08872ca7..843da93b01 100644 --- a/test/cases/safety/slice sentinel mismatch - floats.zig +++ b/test/cases/safety/slice sentinel mismatch - floats.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "sentinel mismatch: expected 1.20000004e+00, found 4.0e+00")) { std.process.exit(0); diff --git a/test/cases/safety/slice sentinel mismatch - optional pointers.zig b/test/cases/safety/slice sentinel mismatch - optional pointers.zig index fbc6fcf428..6be303d9aa 100644 --- a/test/cases/safety/slice sentinel mismatch - optional pointers.zig +++ b/test/cases/safety/slice sentinel mismatch - optional pointers.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "sentinel mismatch: expected null, found i32@10")) { std.process.exit(0); diff --git a/test/cases/safety/slice slice sentinel mismatch.zig b/test/cases/safety/slice slice sentinel mismatch.zig index b1bca1a11f..635706b2c5 100644 --- a/test/cases/safety/slice slice sentinel mismatch.zig +++ b/test/cases/safety/slice slice sentinel mismatch.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "sentinel mismatch: expected 0, found 4")) { std.process.exit(0); diff --git a/test/cases/safety/slice with sentinel out of bounds - runtime len.zig b/test/cases/safety/slice with sentinel out of bounds - runtime len.zig index 524c69d7b7..2f27bebd55 100644 --- a/test/cases/safety/slice with sentinel out of bounds - runtime len.zig +++ b/test/cases/safety/slice with sentinel out of bounds - runtime len.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "index out of bounds: index 5, len 4")) { std.process.exit(0); diff --git a/test/cases/safety/slice with sentinel out of bounds.zig b/test/cases/safety/slice with sentinel out of bounds.zig index 636235a5b3..1683dc9d3f 100644 --- a/test/cases/safety/slice with sentinel out of bounds.zig +++ b/test/cases/safety/slice with sentinel out of bounds.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "index out of bounds: index 5, len 4")) { std.process.exit(0); diff --git a/test/cases/safety/slicing null C pointer - runtime len.zig b/test/cases/safety/slicing null C pointer - runtime len.zig index 2767253612..eda9de20d2 100644 --- a/test/cases/safety/slicing null C pointer - runtime len.zig +++ b/test/cases/safety/slicing null C pointer - runtime len.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "attempt to use null value")) { std.process.exit(0); diff --git a/test/cases/safety/slicing null C pointer.zig b/test/cases/safety/slicing null C pointer.zig index f5041adae7..6ef049c6a1 100644 --- a/test/cases/safety/slicing null C pointer.zig +++ b/test/cases/safety/slicing null C pointer.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "attempt to use null value")) { std.process.exit(0); diff --git a/test/cases/safety/switch on corrupted enum value.zig b/test/cases/safety/switch on corrupted enum value.zig index fd94976763..2240fe0c8e 100644 --- a/test/cases/safety/switch on corrupted enum value.zig +++ b/test/cases/safety/switch on corrupted enum value.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "switch on corrupt value")) { std.process.exit(0); diff --git a/test/cases/safety/switch on corrupted union value.zig b/test/cases/safety/switch on corrupted union value.zig index 059f0dc042..bfb755514a 100644 --- a/test/cases/safety/switch on corrupted union value.zig +++ b/test/cases/safety/switch on corrupted union value.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "switch on corrupt value")) { std.process.exit(0); diff --git a/test/cases/safety/truncating vector cast.zig b/test/cases/safety/truncating vector cast.zig index 5985952e02..e81a6e64ef 100644 --- a/test/cases/safety/truncating vector cast.zig +++ b/test/cases/safety/truncating vector cast.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "integer cast truncated bits")) { std.process.exit(0); diff --git a/test/cases/safety/unreachable.zig b/test/cases/safety/unreachable.zig index f752016aad..492f7958b1 100644 --- a/test/cases/safety/unreachable.zig +++ b/test/cases/safety/unreachable.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "reached unreachable code")) { std.process.exit(0); diff --git a/test/cases/safety/unsigned integer not fitting in cast to signed integer - same bit count.zig b/test/cases/safety/unsigned integer not fitting in cast to signed integer - same bit count.zig index ca901560f0..f370f76557 100644 --- a/test/cases/safety/unsigned integer not fitting in cast to signed integer - same bit count.zig +++ b/test/cases/safety/unsigned integer not fitting in cast to signed integer - same bit count.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "integer cast truncated bits")) { std.process.exit(0); diff --git a/test/cases/safety/unsigned shift left overflow.zig b/test/cases/safety/unsigned shift left overflow.zig index 9d6b6a3c48..d38d8f6ecf 100644 --- a/test/cases/safety/unsigned shift left overflow.zig +++ b/test/cases/safety/unsigned shift left overflow.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "left shift overflowed bits")) { std.process.exit(0); diff --git a/test/cases/safety/unsigned shift right overflow.zig b/test/cases/safety/unsigned shift right overflow.zig index 500e82866b..121797a17d 100644 --- a/test/cases/safety/unsigned shift right overflow.zig +++ b/test/cases/safety/unsigned shift right overflow.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "right shift overflowed bits")) { std.process.exit(0); diff --git a/test/cases/safety/unsigned-signed vector cast.zig b/test/cases/safety/unsigned-signed vector cast.zig index eb3995269f..d4b80fb05c 100644 --- a/test/cases/safety/unsigned-signed vector cast.zig +++ b/test/cases/safety/unsigned-signed vector cast.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "integer cast truncated bits")) { std.process.exit(0); diff --git a/test/cases/safety/unwrap error switch.zig b/test/cases/safety/unwrap error switch.zig new file mode 100644 index 0000000000..0723a9fb24 --- /dev/null +++ b/test/cases/safety/unwrap error switch.zig @@ -0,0 +1,21 @@ +const std = @import("std"); + +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { + _ = stack_trace; + if (std.mem.eql(u8, message, "attempt to unwrap error: Whatever")) { + std.process.exit(0); + } + std.process.exit(1); +} +pub fn main() !void { + bar() catch |err| switch (err) { + error.Whatever => unreachable, + }; + return error.TestFailed; +} +fn bar() !void { + return error.Whatever; +} +// run +// backend=llvm +// target=native diff --git a/test/cases/safety/unwrap error.zig b/test/cases/safety/unwrap error.zig index 498461976d..e2d7ea725b 100644 --- a/test/cases/safety/unwrap error.zig +++ b/test/cases/safety/unwrap error.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "attempt to unwrap error: Whatever")) { std.process.exit(0); diff --git a/test/cases/safety/value does not fit in shortening cast - u0.zig b/test/cases/safety/value does not fit in shortening cast - u0.zig index 3ff3aa6e6c..9b303e5cf5 100644 --- a/test/cases/safety/value does not fit in shortening cast - u0.zig +++ b/test/cases/safety/value does not fit in shortening cast - u0.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "integer cast truncated bits")) { std.process.exit(0); diff --git a/test/cases/safety/value does not fit in shortening cast.zig b/test/cases/safety/value does not fit in shortening cast.zig index 510273a57b..0e98a09787 100644 --- a/test/cases/safety/value does not fit in shortening cast.zig +++ b/test/cases/safety/value does not fit in shortening cast.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "integer cast truncated bits")) { std.process.exit(0); diff --git a/test/cases/safety/vector integer addition overflow.zig b/test/cases/safety/vector integer addition overflow.zig index 7e34fa9393..c553b46189 100644 --- a/test/cases/safety/vector integer addition overflow.zig +++ b/test/cases/safety/vector integer addition overflow.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "integer overflow")) { std.process.exit(0); diff --git a/test/cases/safety/vector integer multiplication overflow.zig b/test/cases/safety/vector integer multiplication overflow.zig index a2a74072b3..4549f7c3e3 100644 --- a/test/cases/safety/vector integer multiplication overflow.zig +++ b/test/cases/safety/vector integer multiplication overflow.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "integer overflow")) { std.process.exit(0); diff --git a/test/cases/safety/vector integer negation overflow.zig b/test/cases/safety/vector integer negation overflow.zig index 7f59982372..8c2c160c68 100644 --- a/test/cases/safety/vector integer negation overflow.zig +++ b/test/cases/safety/vector integer negation overflow.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "integer overflow")) { std.process.exit(0); diff --git a/test/cases/safety/vector integer subtraction overflow.zig b/test/cases/safety/vector integer subtraction overflow.zig index dbfee3af1e..bc475d9800 100644 --- a/test/cases/safety/vector integer subtraction overflow.zig +++ b/test/cases/safety/vector integer subtraction overflow.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "integer overflow")) { std.process.exit(0); diff --git a/test/cases/safety/zero casted to error.zig b/test/cases/safety/zero casted to error.zig index 3a2edf834a..c1be6856a7 100644 --- a/test/cases/safety/zero casted to error.zig +++ b/test/cases/safety/zero casted to error.zig @@ -1,6 +1,6 @@ const std = @import("std"); -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = stack_trace; if (std.mem.eql(u8, message, "invalid error code")) { std.process.exit(0); diff --git a/test/cli.zig b/test/cli.zig index 979478c786..df1a1497e1 100644 --- a/test/cli.zig +++ b/test/cli.zig @@ -120,7 +120,7 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void { \\ return num * num; \\} \\extern fn zig_panic() noreturn; - \\pub fn panic(msg: []const u8, error_return_trace: ?*@import("std").builtin.StackTrace) noreturn { + \\pub fn panic(msg: []const u8, error_return_trace: ?*@import("std").builtin.StackTrace, _: ?usize) noreturn { \\ _ = msg; \\ _ = error_return_trace; \\ zig_panic(); diff --git a/test/standalone/issue_339/test.zig b/test/standalone/issue_339/test.zig index 5e0aafc182..e28839209c 100644 --- a/test/standalone/issue_339/test.zig +++ b/test/standalone/issue_339/test.zig @@ -1,5 +1,5 @@ const StackTrace = @import("std").builtin.StackTrace; -pub fn panic(msg: []const u8, stack_trace: ?*StackTrace) noreturn { +pub fn panic(msg: []const u8, stack_trace: ?*StackTrace, _: ?usize) noreturn { _ = msg; _ = stack_trace; @breakpoint(); diff --git a/test/standalone/issue_8550/main.zig b/test/standalone/issue_8550/main.zig index 615e9aed6a..1f64f03cf2 100644 --- a/test/standalone/issue_8550/main.zig +++ b/test/standalone/issue_8550/main.zig @@ -4,7 +4,7 @@ export fn main(r0: u32, r1: u32, atags: u32) callconv(.C) noreturn { _ = atags; unreachable; // never gets run so it doesn't matter } -pub fn panic(msg: []const u8, error_return_trace: ?*@import("std").builtin.StackTrace) noreturn { +pub fn panic(msg: []const u8, error_return_trace: ?*@import("std").builtin.StackTrace, _: ?usize) noreturn { _ = msg; _ = error_return_trace; while (true) {} |
