aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/align.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-07-31 18:25:27 -0700
committerAndrew Kelley <andrew@ziglang.org>2023-08-01 00:39:30 -0700
commit4f6013bf50e1b99b5c9ea238a2165bfe41fc57d4 (patch)
treeb56fec06557c59b22580db67fc5caa31a8a4d228 /test/behavior/align.zig
parente84cda0ebf8886346d42db78e8f3eb8d0bf515bd (diff)
downloadzig-4f6013bf50e1b99b5c9ea238a2165bfe41fc57d4.tar.gz
zig-4f6013bf50e1b99b5c9ea238a2165bfe41fc57d4.zip
add behavior test for sub-aligned field access
The workaround in std.zig.Server remains because the C backend is not passing the new test. see #14904
Diffstat (limited to 'test/behavior/align.zig')
-rw-r--r--test/behavior/align.zig22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/behavior/align.zig b/test/behavior/align.zig
index a5e0369ae7..ee6033ede4 100644
--- a/test/behavior/align.zig
+++ b/test/behavior/align.zig
@@ -593,3 +593,25 @@ test "alignment of slice element" {
const a: []align(1024) const u8 = undefined;
try expect(@TypeOf(&a[0]) == *align(1024) const u8);
}
+
+test "sub-aligned pointer field access" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
+
+ // Originally reported at https://github.com/ziglang/zig/issues/14904
+
+ const Header = extern struct {
+ tag: u32,
+ bytes_len: u32,
+ };
+ var buf: [9]u8 align(4) = .{ 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+ const ptr: *align(1) Header = @ptrCast(buf[1..][0..8]);
+ const x = ptr.bytes_len;
+ switch (builtin.cpu.arch.endian()) {
+ .Big => try expect(x == 0x06070809),
+ .Little => try expect(x == 0x09080706),
+ }
+}