| ... | @@ -593,3 +593,25 @@ test "alignment of slice element" { | ... | @@ -593,3 +593,25 @@ test "alignment of slice element" { |
| 593 | const a: []align(1024) const u8 = undefined; | 593 | const a: []align(1024) const u8 = undefined; |
| 594 | try expect(@TypeOf(&a[0]) == *align(1024) const u8); | 594 | try expect(@TypeOf(&a[0]) == *align(1024) const u8); |
| 595 | } | 595 | } |
| | 596 | |
| | 597 | test "sub-aligned pointer field access" { |
| | 598 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; |
| | 599 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| | 600 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; |
| | 601 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| | 602 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; |
| | 603 | |
| | 604 | // Originally reported at https://github.com/ziglang/zig/issues/14904 |
| | 605 | |
| | 606 | const Header = extern struct { |
| | 607 | tag: u32, |
| | 608 | bytes_len: u32, |
| | 609 | }; |
| | 610 | var buf: [9]u8 align(4) = .{ 1, 2, 3, 4, 5, 6, 7, 8, 9 }; |
| | 611 | const ptr: *align(1) Header = @ptrCast(buf[1..][0..8]); |
| | 612 | const x = ptr.bytes_len; |
| | 613 | switch (builtin.cpu.arch.endian()) { |
| | 614 | .Big => try expect(x == 0x06070809), |
| | 615 | .Little => try expect(x == 0x09080706), |
| | 616 | } |
| | 617 | } |