mirror of
https://github.com/ziglang/zig.git
synced 2026-01-13 10:55:11 +00:00
* `std.builtin.Panic` -> `std.builtin.panic`, because it is a namespace. * `root.Panic` -> `root.panic` for the same reason. There are type checks so that we still allow the legacy `pub fn panic` strategy in the 0.14.0 release. * `std.debug.SimplePanic` -> `std.debug.simple_panic`, same reason. * `std.debug.NoPanic` -> `std.debug.no_panic`, same reason. * `std.debug.FormattedPanic` is now a function `std.debug.FullPanic` which takes as input a `panicFn` and returns a namespace with all the panic functions. This handles the incredibly common case of just wanting to override how the message is printed, whilst keeping nice formatted panics. * Remove `std.builtin.panic.messages`; now, every safety panic has its own function. This reduces binary bloat, as calls to these functions no longer need to prepare any arguments (aside from the error return trace). * Remove some legacy declarations, since a zig1.wasm update has happened. Most of these were related to the panic handler, but a quick grep for "zig1" brought up a couple more results too. Also, add some missing type checks to Sema. Resolves: #22584 formatted -> full
142 lines
6.0 KiB
Plaintext
142 lines
6.0 KiB
Plaintext
#target=x86_64-linux-selfhosted
|
|
#target=x86_64-linux-cbe
|
|
#target=x86_64-windows-cbe
|
|
#update=initial version
|
|
#file=main.zig
|
|
pub fn main() !u8 {
|
|
var a: u8 = undefined;
|
|
a = 255;
|
|
_ = a + 1;
|
|
return 1;
|
|
}
|
|
const no_panic = std.debug.no_panic;
|
|
pub const panic = struct {
|
|
pub const call = myPanic;
|
|
pub fn integerOverflow() noreturn {
|
|
@panic("integer overflow");
|
|
}
|
|
pub const sentinelMismatch = no_panic.sentinelMismatch;
|
|
pub const unwrapError = no_panic.unwrapError;
|
|
pub const outOfBounds = no_panic.outOfBounds;
|
|
pub const startGreaterThanEnd = no_panic.startGreaterThanEnd;
|
|
pub const inactiveUnionField = no_panic.inactiveUnionField;
|
|
pub const reachedUnreachable = no_panic.reachedUnreachable;
|
|
pub const unwrapNull = no_panic.unwrapNull;
|
|
pub const castToNull = no_panic.castToNull;
|
|
pub const incorrectAlignment = no_panic.incorrectAlignment;
|
|
pub const invalidErrorCode = no_panic.invalidErrorCode;
|
|
pub const castTruncatedData = no_panic.castTruncatedData;
|
|
pub const negativeToUnsigned = no_panic.negativeToUnsigned;
|
|
pub const shlOverflow = no_panic.shlOverflow;
|
|
pub const shrOverflow = no_panic.shrOverflow;
|
|
pub const divideByZero = no_panic.divideByZero;
|
|
pub const exactDivisionRemainder = no_panic.exactDivisionRemainder;
|
|
pub const integerPartOutOfBounds = no_panic.integerPartOutOfBounds;
|
|
pub const corruptSwitch = no_panic.corruptSwitch;
|
|
pub const shiftRhsTooBig = no_panic.shiftRhsTooBig;
|
|
pub const invalidEnumValue = no_panic.invalidEnumValue;
|
|
pub const forLenMismatch = no_panic.forLenMismatch;
|
|
pub const memcpyLenMismatch = no_panic.memcpyLenMismatch;
|
|
pub const memcpyAlias = no_panic.memcpyAlias;
|
|
pub const noreturnReturned = no_panic.noreturnReturned;
|
|
};
|
|
fn myPanic(msg: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noreturn {
|
|
std.io.getStdOut().writer().print("panic message: {s}\n", .{msg}) catch {};
|
|
std.process.exit(0);
|
|
}
|
|
const std = @import("std");
|
|
#expect_stdout="panic message: integer overflow\n"
|
|
|
|
#update=change the panic handler body
|
|
#file=main.zig
|
|
pub fn main() !u8 {
|
|
var a: u8 = undefined;
|
|
a = 255;
|
|
_ = a + 1;
|
|
return 1;
|
|
}
|
|
const no_panic = std.debug.no_panic;
|
|
pub const panic = struct {
|
|
pub const call = myPanic;
|
|
pub fn integerOverflow() noreturn {
|
|
@panic("integer overflow");
|
|
}
|
|
pub const sentinelMismatch = no_panic.sentinelMismatch;
|
|
pub const unwrapError = no_panic.unwrapError;
|
|
pub const outOfBounds = no_panic.outOfBounds;
|
|
pub const startGreaterThanEnd = no_panic.startGreaterThanEnd;
|
|
pub const inactiveUnionField = no_panic.inactiveUnionField;
|
|
pub const reachedUnreachable = no_panic.reachedUnreachable;
|
|
pub const unwrapNull = no_panic.unwrapNull;
|
|
pub const castToNull = no_panic.castToNull;
|
|
pub const incorrectAlignment = no_panic.incorrectAlignment;
|
|
pub const invalidErrorCode = no_panic.invalidErrorCode;
|
|
pub const castTruncatedData = no_panic.castTruncatedData;
|
|
pub const negativeToUnsigned = no_panic.negativeToUnsigned;
|
|
pub const shlOverflow = no_panic.shlOverflow;
|
|
pub const shrOverflow = no_panic.shrOverflow;
|
|
pub const divideByZero = no_panic.divideByZero;
|
|
pub const exactDivisionRemainder = no_panic.exactDivisionRemainder;
|
|
pub const integerPartOutOfBounds = no_panic.integerPartOutOfBounds;
|
|
pub const corruptSwitch = no_panic.corruptSwitch;
|
|
pub const shiftRhsTooBig = no_panic.shiftRhsTooBig;
|
|
pub const invalidEnumValue = no_panic.invalidEnumValue;
|
|
pub const forLenMismatch = no_panic.forLenMismatch;
|
|
pub const memcpyLenMismatch = no_panic.memcpyLenMismatch;
|
|
pub const memcpyAlias = no_panic.memcpyAlias;
|
|
pub const noreturnReturned = no_panic.noreturnReturned;
|
|
};
|
|
fn myPanic(msg: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noreturn {
|
|
std.io.getStdOut().writer().print("new panic message: {s}\n", .{msg}) catch {};
|
|
std.process.exit(0);
|
|
}
|
|
const std = @import("std");
|
|
#expect_stdout="new panic message: integer overflow\n"
|
|
|
|
#update=change the panic handler function value
|
|
#file=main.zig
|
|
pub fn main() !u8 {
|
|
var a: u8 = undefined;
|
|
a = 255;
|
|
_ = a + 1;
|
|
return 1;
|
|
}
|
|
const no_panic = std.debug.no_panic;
|
|
pub const panic = struct {
|
|
pub const call = myPanicNew;
|
|
pub fn integerOverflow() noreturn {
|
|
@panic("integer overflow");
|
|
}
|
|
pub const sentinelMismatch = std.debug.no_panic.sentinelMismatch;
|
|
pub const unwrapError = std.debug.no_panic.unwrapError;
|
|
pub const outOfBounds = std.debug.no_panic.outOfBounds;
|
|
pub const startGreaterThanEnd = std.debug.no_panic.startGreaterThanEnd;
|
|
pub const inactiveUnionField = std.debug.no_panic.inactiveUnionField;
|
|
pub const messages = std.debug.no_panic.messages;
|
|
pub const reachedUnreachable = no_panic.reachedUnreachable;
|
|
pub const unwrapNull = no_panic.unwrapNull;
|
|
pub const castToNull = no_panic.castToNull;
|
|
pub const incorrectAlignment = no_panic.incorrectAlignment;
|
|
pub const invalidErrorCode = no_panic.invalidErrorCode;
|
|
pub const castTruncatedData = no_panic.castTruncatedData;
|
|
pub const negativeToUnsigned = no_panic.negativeToUnsigned;
|
|
pub const shlOverflow = no_panic.shlOverflow;
|
|
pub const shrOverflow = no_panic.shrOverflow;
|
|
pub const divideByZero = no_panic.divideByZero;
|
|
pub const exactDivisionRemainder = no_panic.exactDivisionRemainder;
|
|
pub const integerPartOutOfBounds = no_panic.integerPartOutOfBounds;
|
|
pub const corruptSwitch = no_panic.corruptSwitch;
|
|
pub const shiftRhsTooBig = no_panic.shiftRhsTooBig;
|
|
pub const invalidEnumValue = no_panic.invalidEnumValue;
|
|
pub const forLenMismatch = no_panic.forLenMismatch;
|
|
pub const memcpyLenMismatch = no_panic.memcpyLenMismatch;
|
|
pub const memcpyAlias = no_panic.memcpyAlias;
|
|
pub const noreturnReturned = no_panic.noreturnReturned;
|
|
};
|
|
fn myPanicNew(msg: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noreturn {
|
|
std.io.getStdOut().writer().print("third panic message: {s}\n", .{msg}) catch {};
|
|
std.process.exit(0);
|
|
}
|
|
const std = @import("std");
|
|
#expect_stdout="third panic message: integer overflow\n"
|