diff options
| author | Alex Kladov <aleksey.kladov@gmail.com> | 2023-06-28 01:44:02 +0100 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2023-06-28 16:36:32 +0200 |
| commit | 4620972d086ebb3b7686a79914876488c6dfd171 (patch) | |
| tree | 8f2f47f0a02deb0f535f77b38a801d0259ac1745 /test/behavior/struct.zig | |
| parent | 28f515acd7bb6e008fcb2e9f760053f0c9e97992 (diff) | |
| download | zig-4620972d086ebb3b7686a79914876488c6dfd171.tar.gz zig-4620972d086ebb3b7686a79914876488c6dfd171.zip | |
Sema: preserve extern struct field alignment
In
extern struct { x: u32, y: u16 }
we actually know that y's alignment is `@alignOf(u32)`, and not just
`@alignOf(u16)`.
closes: #16134
Diffstat (limited to 'test/behavior/struct.zig')
| -rw-r--r-- | test/behavior/struct.zig | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig index 1335498ca4..ab7b97ae94 100644 --- a/test/behavior/struct.zig +++ b/test/behavior/struct.zig @@ -1680,9 +1680,9 @@ test "extern struct field pointer has correct alignment" { const S = struct { fn doTheTest() !void { - var a: extern struct { x: u32, y: u32 } = .{ .x = 1, .y = 2 }; - var b: extern struct { x: u32, y: u32 } align(1) = .{ .x = 3, .y = 4 }; - var c: extern struct { x: u32, y: u32 } align(64) = .{ .x = 5, .y = 6 }; + var a: extern struct { x: u32, y: u16 } = .{ .x = 1, .y = 2 }; + var b: extern struct { x: u32, y: u16 } align(1) = .{ .x = 3, .y = 4 }; + var c: extern struct { x: u32, y: u16 } align(64) = .{ .x = 5, .y = 6 }; const axp = &a.x; const bxp = &b.x; @@ -1693,18 +1693,19 @@ test "extern struct field pointer has correct alignment" { comptime assert(@TypeOf(axp) == *u32); comptime assert(@TypeOf(bxp) == *align(1) u32); - comptime assert(@TypeOf(cxp) == *align(64) u32); // first field, inherits larger alignment - comptime assert(@TypeOf(ayp) == *u32); - comptime assert(@TypeOf(byp) == *align(1) u32); - comptime assert(@TypeOf(cyp) == *u32); + comptime assert(@TypeOf(cxp) == *align(64) u32); + + comptime assert(@TypeOf(ayp) == *align(@alignOf(u32)) u16); + comptime assert(@TypeOf(byp) == *align(1) u16); + comptime assert(@TypeOf(cyp) == *align(@alignOf(u32)) u16); try expectEqual(@as(u32, 1), axp.*); try expectEqual(@as(u32, 3), bxp.*); try expectEqual(@as(u32, 5), cxp.*); - try expectEqual(@as(u32, 2), ayp.*); - try expectEqual(@as(u32, 4), byp.*); - try expectEqual(@as(u32, 6), cyp.*); + try expectEqual(@as(u16, 2), ayp.*); + try expectEqual(@as(u16, 4), byp.*); + try expectEqual(@as(u16, 6), cyp.*); } }; |
