master
  1#target=x86_64-linux-selfhosted
  2#target=x86_64-windows-selfhosted
  3#target=x86_64-linux-cbe
  4#target=x86_64-windows-cbe
  5#update=initial version
  6#file=main.zig
  7pub fn main() !u8 {
  8    var a: u8 = undefined;
  9    a = 255;
 10    _ = a + 1;
 11    return 1;
 12}
 13const no_panic = std.debug.no_panic;
 14pub const panic = struct {
 15    pub const call = myPanic;
 16    pub fn integerOverflow() noreturn {
 17        @panic("integer overflow");
 18    }
 19    pub const sentinelMismatch = no_panic.sentinelMismatch;
 20    pub const unwrapError = no_panic.unwrapError;
 21    pub const outOfBounds = no_panic.outOfBounds;
 22    pub const startGreaterThanEnd = no_panic.startGreaterThanEnd;
 23    pub const inactiveUnionField = no_panic.inactiveUnionField;
 24    pub const sliceCastLenRemainder = no_panic.sliceCastLenRemainder;
 25    pub const reachedUnreachable = no_panic.reachedUnreachable;
 26    pub const unwrapNull = no_panic.unwrapNull;
 27    pub const castToNull = no_panic.castToNull;
 28    pub const incorrectAlignment = no_panic.incorrectAlignment;
 29    pub const invalidErrorCode = no_panic.invalidErrorCode;
 30    pub const integerOutOfBounds = no_panic.integerOutOfBounds;
 31    pub const shlOverflow = no_panic.shlOverflow;
 32    pub const shrOverflow = no_panic.shrOverflow;
 33    pub const divideByZero = no_panic.divideByZero;
 34    pub const exactDivisionRemainder = no_panic.exactDivisionRemainder;
 35    pub const integerPartOutOfBounds = no_panic.integerPartOutOfBounds;
 36    pub const corruptSwitch = no_panic.corruptSwitch;
 37    pub const shiftRhsTooBig = no_panic.shiftRhsTooBig;
 38    pub const invalidEnumValue = no_panic.invalidEnumValue;
 39    pub const forLenMismatch = no_panic.forLenMismatch;
 40    pub const copyLenMismatch = no_panic.copyLenMismatch;
 41    pub const memcpyAlias = no_panic.memcpyAlias;
 42    pub const noreturnReturned = no_panic.noreturnReturned;
 43};
 44fn myPanic(msg: []const u8, _: ?usize) noreturn {
 45    var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
 46    stdout_writer.interface.print("panic message: {s}\n", .{msg}) catch {};
 47    std.process.exit(0);
 48}
 49const std = @import("std");
 50#expect_stdout="panic message: integer overflow\n"
 51
 52#update=change the panic handler body
 53#file=main.zig
 54pub fn main() !u8 {
 55    var a: u8 = undefined;
 56    a = 255;
 57    _ = a + 1;
 58    return 1;
 59}
 60const no_panic = std.debug.no_panic;
 61pub const panic = struct {
 62    pub const call = myPanic;
 63    pub fn integerOverflow() noreturn {
 64        @panic("integer overflow");
 65    }
 66    pub const sentinelMismatch = no_panic.sentinelMismatch;
 67    pub const unwrapError = no_panic.unwrapError;
 68    pub const outOfBounds = no_panic.outOfBounds;
 69    pub const startGreaterThanEnd = no_panic.startGreaterThanEnd;
 70    pub const inactiveUnionField = no_panic.inactiveUnionField;
 71    pub const sliceCastLenRemainder = no_panic.sliceCastLenRemainder;
 72    pub const reachedUnreachable = no_panic.reachedUnreachable;
 73    pub const unwrapNull = no_panic.unwrapNull;
 74    pub const castToNull = no_panic.castToNull;
 75    pub const incorrectAlignment = no_panic.incorrectAlignment;
 76    pub const invalidErrorCode = no_panic.invalidErrorCode;
 77    pub const integerOutOfBounds = no_panic.integerOutOfBounds;
 78    pub const shlOverflow = no_panic.shlOverflow;
 79    pub const shrOverflow = no_panic.shrOverflow;
 80    pub const divideByZero = no_panic.divideByZero;
 81    pub const exactDivisionRemainder = no_panic.exactDivisionRemainder;
 82    pub const integerPartOutOfBounds = no_panic.integerPartOutOfBounds;
 83    pub const corruptSwitch = no_panic.corruptSwitch;
 84    pub const shiftRhsTooBig = no_panic.shiftRhsTooBig;
 85    pub const invalidEnumValue = no_panic.invalidEnumValue;
 86    pub const forLenMismatch = no_panic.forLenMismatch;
 87    pub const copyLenMismatch = no_panic.copyLenMismatch;
 88    pub const memcpyAlias = no_panic.memcpyAlias;
 89    pub const noreturnReturned = no_panic.noreturnReturned;
 90};
 91fn myPanic(msg: []const u8, _: ?usize) noreturn {
 92    var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
 93    stdout_writer.interface.print("new panic message: {s}\n", .{msg}) catch {};
 94    std.process.exit(0);
 95}
 96const std = @import("std");
 97#expect_stdout="new panic message: integer overflow\n"
 98
 99#update=change the panic handler function value
100#file=main.zig
101pub fn main() !u8 {
102    var a: u8 = undefined;
103    a = 255;
104    _ = a + 1;
105    return 1;
106}
107const no_panic = std.debug.no_panic;
108pub const panic = struct {
109    pub const call = myPanicNew;
110    pub fn integerOverflow() noreturn {
111        @panic("integer overflow");
112    }
113    pub const sentinelMismatch = std.debug.no_panic.sentinelMismatch;
114    pub const unwrapError = std.debug.no_panic.unwrapError;
115    pub const outOfBounds = std.debug.no_panic.outOfBounds;
116    pub const startGreaterThanEnd = std.debug.no_panic.startGreaterThanEnd;
117    pub const inactiveUnionField = std.debug.no_panic.inactiveUnionField;
118    pub const sliceCastLenRemainder = no_panic.sliceCastLenRemainder;
119    pub const reachedUnreachable = no_panic.reachedUnreachable;
120    pub const unwrapNull = no_panic.unwrapNull;
121    pub const castToNull = no_panic.castToNull;
122    pub const incorrectAlignment = no_panic.incorrectAlignment;
123    pub const invalidErrorCode = no_panic.invalidErrorCode;
124    pub const integerOutOfBounds = no_panic.integerOutOfBounds;
125    pub const shlOverflow = no_panic.shlOverflow;
126    pub const shrOverflow = no_panic.shrOverflow;
127    pub const divideByZero = no_panic.divideByZero;
128    pub const exactDivisionRemainder = no_panic.exactDivisionRemainder;
129    pub const integerPartOutOfBounds = no_panic.integerPartOutOfBounds;
130    pub const corruptSwitch = no_panic.corruptSwitch;
131    pub const shiftRhsTooBig = no_panic.shiftRhsTooBig;
132    pub const invalidEnumValue = no_panic.invalidEnumValue;
133    pub const forLenMismatch = no_panic.forLenMismatch;
134    pub const copyLenMismatch = no_panic.copyLenMismatch;
135    pub const memcpyAlias = no_panic.memcpyAlias;
136    pub const noreturnReturned = no_panic.noreturnReturned;
137};
138fn myPanicNew(msg: []const u8, _: ?usize) noreturn {
139    var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
140    stdout_writer.interface.print("third panic message: {s}\n", .{msg}) catch {};
141    std.process.exit(0);
142}
143const std = @import("std");
144#expect_stdout="third panic message: integer overflow\n"