zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 83a2c41cd5230561899f9a3accdbb9e1a52af836 (tree)
parent 4751356d7f1da157665d37e29216628e61ddf079
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Thu, 26 May 2022 21:55:51 -0700

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.

Diffstat:
Mtest/behavior/align.zig | 22+++++++++-------------
1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/test/behavior/align.zig b/test/behavior/align.zig @@ -18,20 +18,16 @@ test "global variable alignment" { } } -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; +test "slicing array of length 1 can not assume runtime index is always zero" { + if (builtin.zig_backend == .stage1) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO - var runtime_zero: usize = 0; - const slice = @as(*align(4) [1]u8, &foo)[runtime_zero..]; - comptime try expect(@TypeOf(slice) == []align(4) u8); + var runtime_index: usize = 1; + const slice = @as(*align(4) [1]u8, &foo)[runtime_index..]; + try expect(@TypeOf(slice) == []u8); + try expect(slice.len == 0); + try expect(@truncate(u2, @ptrToInt(slice.ptr) - 1) == 0); } test "default alignment allows unspecified in type syntax" {