diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-05-17 01:52:02 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-05-17 23:50:38 -0700 |
| commit | b6798c26efc4689cf35c5f4ac0436b4510a1f813 (patch) | |
| tree | 9507321f623264de9c5bef41ff53c19c88f09bd3 /test/behavior/align.zig | |
| parent | 95f5e17e49d32a301d6a9d6f9948719d65469b09 (diff) | |
| download | zig-b6798c26efc4689cf35c5f4ac0436b4510a1f813.tar.gz zig-b6798c26efc4689cf35c5f4ac0436b4510a1f813.zip | |
stage2: fix pointer arithmetic result type
This makes it so the result of doing pointer arithmetic creates a new
pointer type that has adjusted alignment.
Diffstat (limited to 'test/behavior/align.zig')
| -rw-r--r-- | test/behavior/align.zig | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/test/behavior/align.zig b/test/behavior/align.zig index ffe53f9088..5b753aa737 100644 --- a/test/behavior/align.zig +++ b/test/behavior/align.zig @@ -16,11 +16,22 @@ test "global variable alignment" { const slice = @as(*align(4) [1]u8, &foo)[0..]; comptime try expect(@TypeOf(slice) == *align(4) [1]u8); } - { - var runtime_zero: usize = 0; - const slice = @as(*align(4) [1]u8, &foo)[runtime_zero..]; - comptime try expect(@TypeOf(slice) == []align(4) u8); - } +} + +test "slicing array of length 1 can assume runtime index is always zero" { + if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO + + // TODO reevaluate this test case, because notice that you can + // change `runtime_zero` to be `1` and the test still passes for stage1. + // Reconsider also this code: + // var array: [4]u8 = undefined; + // var runtime: usize = 4; + // var ptr = array[runtime..]; + // _ = ptr; + + var runtime_zero: usize = 0; + const slice = @as(*align(4) [1]u8, &foo)[runtime_zero..]; + comptime try expect(@TypeOf(slice) == []align(4) u8); } test "default alignment allows unspecified in type syntax" { |
