| 1 | const std = @import("std"); |
| 2 | |
| 3 | pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { |
| 4 | _ = stack_trace; |
| 5 | if (std.mem.eql(u8, message, "incorrect alignment")) { |
| 6 | std.process.exit(0); |
| 7 | } |
| 8 | std.process.exit(1); |
| 9 | } |
| 10 | |
| 11 | pub fn main() !void { |
| 12 | var array align(4) = [_]u32{ 0x11111111, 0x11111111 }; |
| 13 | const bytes = std.mem.sliceAsBytes(array[0..]); |
| 14 | if (foo(bytes) != 0x11111111) return error.Wrong; |
| 15 | return error.TestFailed; |
| 16 | } |
| 17 | fn foo(bytes: []u8) u32 { |
| 18 | const slice4 = bytes[1..5]; |
| 19 | const aligned: *align(4) [4]u8 = @alignCast(slice4); |
| 20 | const int_slice = std.mem.bytesAsSlice(u32, aligned); |
| 21 | return int_slice[0]; |
| 22 | } |
| 23 | // run |
| 24 | // backend=selfhosted,llvm |
| 25 | // target=x86_64-linux,aarch64-linux,wasm32-wasi |