diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2023-09-21 02:00:52 +0100 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-09-21 14:48:41 -0700 |
| commit | 1b672e41c528b0aa225cbe07c61203d04b2d9034 (patch) | |
| tree | 080cac4fbde495c9b216fac1cd67e84799740059 /test/behavior/alignof.zig | |
| parent | cd242b7440e11d9997c33296b3974dfb1fbd5d95 (diff) | |
| download | zig-1b672e41c528b0aa225cbe07c61203d04b2d9034.tar.gz zig-1b672e41c528b0aa225cbe07c61203d04b2d9034.zip | |
InternPool,Sema,type,llvm: alignment fixes
This changeset fixes the handling of alignment in several places. The
new rules are:
* `@alignOf(T)` where `T` is a runtime zero-bit type is at least 1,
maybe greater.
* Zero-bit fields in `extern` structs *do* force alignment, potentially
offsetting following fields.
* Zero-bit fields *do* have addresses within structs which can be
observed and are consistent with `@offsetOf`.
These are not necessarily all implemented correctly yet (see disabled
test), but this commit fixes all regressions compared to master, and
makes one new test pass.
Diffstat (limited to 'test/behavior/alignof.zig')
| -rw-r--r-- | test/behavior/alignof.zig | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/test/behavior/alignof.zig b/test/behavior/alignof.zig index b414b7e056..0443b2d6b3 100644 --- a/test/behavior/alignof.zig +++ b/test/behavior/alignof.zig @@ -18,24 +18,13 @@ test "@alignOf(T) before referencing T" { } test "comparison of @alignOf(T) against zero" { - { - const T = struct { x: u32 }; - try expect(!(@alignOf(T) == 0)); - try expect(@alignOf(T) != 0); - try expect(!(@alignOf(T) < 0)); - try expect(!(@alignOf(T) <= 0)); - try expect(@alignOf(T) > 0); - try expect(@alignOf(T) >= 0); - } - { - const T = struct {}; - try expect(@alignOf(T) == 0); - try expect(!(@alignOf(T) != 0)); - try expect(!(@alignOf(T) < 0)); - try expect(@alignOf(T) <= 0); - try expect(!(@alignOf(T) > 0)); - try expect(@alignOf(T) >= 0); - } + const T = struct { x: u32 }; + try expect(!(@alignOf(T) == 0)); + try expect(@alignOf(T) != 0); + try expect(!(@alignOf(T) < 0)); + try expect(!(@alignOf(T) <= 0)); + try expect(@alignOf(T) > 0); + try expect(@alignOf(T) >= 0); } test "correct alignment for elements and slices of aligned array" { |
