diff options
| author | Veikka Tuominen <git@vexu.eu> | 2023-01-16 19:46:41 +0200 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2023-01-16 19:46:41 +0200 |
| commit | 342bae02d86d9bd9f2db6ae9489021bab28595ae (patch) | |
| tree | 8b50d7cffff029c135a17295c4c324603d2358b1 /test/behavior/struct.zig | |
| parent | 31a2b8c3642f1240a70d78203d568051d4dbcd3f (diff) | |
| download | zig-342bae02d86d9bd9f2db6ae9489021bab28595ae.tar.gz zig-342bae02d86d9bd9f2db6ae9489021bab28595ae.zip | |
Sema: automatically optimize order of struct fields
This is a simple starting version of the optimization described in #168
where the fields are just sorted by order of descending alignment.
Diffstat (limited to 'test/behavior/struct.zig')
| -rw-r--r-- | test/behavior/struct.zig | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig index 20a09f92cc..a32a0ed495 100644 --- a/test/behavior/struct.zig +++ b/test/behavior/struct.zig @@ -1555,3 +1555,21 @@ test "optional generic function label struct field" { }; try expect((Options{}).isFoo.?(u8) == 123); } + +test "struct fields get automatically reordered" { + if (builtin.zig_backend != .stage2_llvm) return error.SkipZigTest; // TODO + + const S1 = struct { + a: u32, + b: u32, + c: bool, + d: bool, + }; + const S2 = struct { + a: u32, + b: bool, + c: u32, + d: bool, + }; + try expect(@sizeOf(S1) == @sizeOf(S2)); +} |
