authorgravatar for mitchell.hashimoto@gmail.comMitchell Hashimoto <mitchell.hashimoto@gmail.com> 2022-03-08 12:05:12-08:00
committergravatar for mitchell.hashimoto@gmail.comMitchell Hashimoto <mitchell.hashimoto@gmail.com> 2022-03-08 12:05:12-08:00
logba62853d26f6a3388a7ad099a1d9091d7eca45c9
tree7472c1c2cebe24fb4fc3283343ae18e36d87d153
parentcd32b11eb8d33225a1a2bc3bc9e0755936a39ade
signaturelock-open Commit is signed but in an unrecognized format.

stage2: sentinel array init must add sentinel to array value

I didn't realize that the `array` value type has the sentinel on it.

2 files changed, 20 insertions(+), 13 deletions(-)

src/Sema.zig+5-10
...@@ -11827,21 +11827,16 @@ fn zirArrayInit(...@@ -11827,21 +11827,16 @@ fn zirArrayInit(
11827 });11827 });
11828 };11828 };
1182911829
11830 const elems = if (!is_sent)11830 const opt_runtime_src: ?LazySrcLoc = for (resolved_args) |arg| {
11831 resolved_args
11832 else
11833 resolved_args[0 .. resolved_args.len - 1];
11834
11835 const opt_runtime_src: ?LazySrcLoc = for (elems) |arg| {
11836 const arg_src = src; // TODO better source location11831 const arg_src = src; // TODO better source location
11837 const comptime_known = try sema.isComptimeKnown(block, arg_src, arg);11832 const comptime_known = try sema.isComptimeKnown(block, arg_src, arg);
11838 if (!comptime_known) break arg_src;11833 if (!comptime_known) break arg_src;
11839 } else null;11834 } else null;
1184011835
11841 const runtime_src = opt_runtime_src orelse {11836 const runtime_src = opt_runtime_src orelse {
11842 const elem_vals = try sema.arena.alloc(Value, elems.len);11837 const elem_vals = try sema.arena.alloc(Value, resolved_args.len);
1184311838
11844 for (elems) |arg, i| {11839 for (resolved_args) |arg, i| {
11845 // We checked that all args are comptime above.11840 // We checked that all args are comptime above.
11846 elem_vals[i] = (sema.resolveMaybeUndefVal(block, src, arg) catch unreachable).?;11841 elem_vals[i] = (sema.resolveMaybeUndefVal(block, src, arg) catch unreachable).?;
11847 }11842 }
...@@ -11868,7 +11863,7 @@ fn zirArrayInit(...@@ -11868,7 +11863,7 @@ fn zirArrayInit(
11868 });11863 });
11869 const elem_ptr_ty_ref = try sema.addType(elem_ptr_ty);11864 const elem_ptr_ty_ref = try sema.addType(elem_ptr_ty);
1187011865
11871 for (elems) |arg, i| {11866 for (resolved_args) |arg, i| {
11872 const index = try sema.addIntUnsigned(Type.usize, i);11867 const index = try sema.addIntUnsigned(Type.usize, i);
11873 const elem_ptr = try block.addPtrElemPtrTypeRef(alloc, index, elem_ptr_ty_ref);11868 const elem_ptr = try block.addPtrElemPtrTypeRef(alloc, index, elem_ptr_ty_ref);
11874 _ = try block.addBinOp(.store, elem_ptr, arg);11869 _ = try block.addBinOp(.store, elem_ptr, arg);
...@@ -11876,7 +11871,7 @@ fn zirArrayInit(...@@ -11876,7 +11871,7 @@ fn zirArrayInit(
11876 return alloc;11871 return alloc;
11877 }11872 }
1187811873
11879 return block.addAggregateInit(array_ty, elems);11874 return block.addAggregateInit(array_ty, resolved_args);
11880}11875}
1188111876
11882fn zirArrayInitAnon(11877fn zirArrayInitAnon(
test/behavior/pointers.zig+15-3
...@@ -317,7 +317,11 @@ test "allow any sentinel" {...@@ -317,7 +317,11 @@ test "allow any sentinel" {
317}317}
318318
319test "pointer sentinel with enums" {319test "pointer sentinel with enums" {
320 if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO320 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
321 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
322 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
323 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
324 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
321325
322 const S = struct {326 const S = struct {
323 const Number = enum {327 const Number = enum {
...@@ -336,7 +340,11 @@ test "pointer sentinel with enums" {...@@ -336,7 +340,11 @@ test "pointer sentinel with enums" {
336}340}
337341
338test "pointer sentinel with optional element" {342test "pointer sentinel with optional element" {
339 if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO343 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
344 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
345 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
346 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
347 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
340348
341 const S = struct {349 const S = struct {
342 fn doTheTest() !void {350 fn doTheTest() !void {
...@@ -349,7 +357,11 @@ test "pointer sentinel with optional element" {...@@ -349,7 +357,11 @@ test "pointer sentinel with optional element" {
349}357}
350358
351test "pointer sentinel with +inf" {359test "pointer sentinel with +inf" {
352 if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO360 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
361 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
362 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
363 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
364 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
353365
354 const S = struct {366 const S = struct {
355 fn doTheTest() !void {367 fn doTheTest() !void {