authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-05-26 21:55:51-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-05-26 21:58:19-07:00
log83a2c41cd5230561899f9a3accdbb9e1a52af836
treef61ae06d60158386c0875b4ab6ff1127b4ed2a63
parent4751356d7f1da157665d37e29216628e61ddf079

fix alignment behavior test case

As demonstrated by this new test case, stage1's functionality is incorrect since it does not handle slicing from len..len correctly. stage2 already has the correct behavior here.

1 files changed, 9 insertions(+), 13 deletions(-)

test/behavior/align.zig+9-13
...@@ -18,20 +18,16 @@ test "global variable alignment" {...@@ -18,20 +18,16 @@ test "global variable alignment" {
18 }18 }
19}19}
2020
21test "slicing array of length 1 can assume runtime index is always zero" {21test "slicing array of length 1 can not assume runtime index is always zero" {
22 if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO22 if (builtin.zig_backend == .stage1) return error.SkipZigTest;
2323 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
24 // TODO reevaluate this test case, because notice that you can24 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
25 // change `runtime_zero` to be `1` and the test still passes for stage1.
26 // Reconsider also this code:
27 // var array: [4]u8 = undefined;
28 // var runtime: usize = 4;
29 // var ptr = array[runtime..];
30 // _ = ptr;
3125
32 var runtime_zero: usize = 0;26 var runtime_index: usize = 1;
33 const slice = @as(*align(4) [1]u8, &foo)[runtime_zero..];27 const slice = @as(*align(4) [1]u8, &foo)[runtime_index..];
34 comptime try expect(@TypeOf(slice) == []align(4) u8);28 try expect(@TypeOf(slice) == []u8);
29 try expect(slice.len == 0);
30 try expect(@truncate(u2, @ptrToInt(slice.ptr) - 1) == 0);
35}31}
3632
37test "default alignment allows unspecified in type syntax" {33test "default alignment allows unspecified in type syntax" {