diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-07-22 11:58:50 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-22 11:58:50 -0700 |
| commit | 5dd59a54238b63cb52bb91d3cf803cb0196abb64 (patch) | |
| tree | f88c35f0ef45664dcfb5cc23fb8a7166eddf761f /test/behavior/struct.zig | |
| parent | d925d19cfcabd96fdc4459e11ecb85a4f42ec655 (diff) | |
| parent | 5cd1ccf4b98a5018b166d7ee214a3686b3a5834d (diff) | |
| download | zig-5dd59a54238b63cb52bb91d3cf803cb0196abb64.tar.gz zig-5dd59a54238b63cb52bb91d3cf803cb0196abb64.zip | |
Merge pull request #12191 from ziglang/underaligned-fields
LLVM: fix lowering of structs with underaligned fields
Diffstat (limited to 'test/behavior/struct.zig')
| -rw-r--r-- | test/behavior/struct.zig | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig index 709c73807b..22d09a066d 100644 --- a/test/behavior/struct.zig +++ b/test/behavior/struct.zig @@ -1372,3 +1372,26 @@ test "struct field init value is size of the struct" { var s: namespace.S = .{ .blah = 1234 }; try expect(s.size == 4); } + +test "under-aligned struct field" { + if (builtin.zig_backend == .stage1) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO + + const U = extern union { + fd: i32, + u32: u32, + u64: u64, + }; + const S = extern struct { + events: u32, + data: U align(4), + }; + var runtime: usize = 1234; + const ptr = &S{ .events = 0, .data = .{ .u64 = runtime } }; + const array = @ptrCast(*const [12]u8, ptr); + const result = std.mem.readIntNative(u64, array[4..12]); + try expect(result == 1234); +} |
