From 032c722d2019a475362c0ae01241a80417bdd8a2 Mon Sep 17 00:00:00 2001 From: sin-ack <77421532+sin-ack@users.noreply.github.com> Date: Sat, 30 Apr 2022 05:53:06 +0300 Subject: Sema: Fix many-pointer array concatenation at comptime (#11512) * Sema: Correctly determine whether array_cat lhs and rhs are single ptrs Many-pointers are also not single-pointers and wouldn't be considered here. This commit makes the conditions use the appropriately-named isSinglePointer instead. * Sema: Correctly obtain ArrayInfo for many-pointer concatenation Many-pointers at comptime have a known size like slices and can be used in array concatenation. This fixes a stage1 regression. * test: Add comptime manyptr concatenation test Co-authored-by: sin-ack --- test/behavior/basic.zig | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'test/behavior/basic.zig') diff --git a/test/behavior/basic.zig b/test/behavior/basic.zig index d608cba98b..12ead179f4 100644 --- a/test/behavior/basic.zig +++ b/test/behavior/basic.zig @@ -709,6 +709,31 @@ test "string concatenation" { try expect(b[len] == 0); } +fn manyptrConcat(comptime s: [*:0]const u8) [*:0]const u8 { + return "very " ++ s; +} + +test "comptime manyptr concatenation" { + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + + const s = "epic"; + const actual = manyptrConcat(s); + const expected = "very epic"; + + const len = mem.len(actual); + const len_with_null = len + 1; + { + var i: u32 = 0; + while (i < len_with_null) : (i += 1) { + try expect(actual[i] == expected[i]); + } + } + try expect(actual[len] == 0); + try expect(expected[len] == 0); +} + test "thread local variable" { if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO -- cgit v1.2.3