aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/array.zig
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2025-07-29 10:04:15 +0100
committermlugg <mlugg@mlugg.co.uk>2025-07-29 15:52:19 +0100
commita8888afcc07479bf779105f977597b29aea3c28f (patch)
treead34e4c4b6fd0864ef6bd1cee22c2abb156f9414 /test/behavior/array.zig
parent3fbdd58a874c6b4dae84bed2ed31c945ff4adb54 (diff)
downloadzig-a8888afcc07479bf779105f977597b29aea3c28f.tar.gz
zig-a8888afcc07479bf779105f977597b29aea3c28f.zip
Sema: remove redundant comptime-known initializer tracking
This logic predates certain Sema enhancements whose behavior it essentially tries to emulate in one specific case in a problematic way. In particular, this logic handled initializing comptime-known `const`s through RLS, which was reworked a few years back in 644041b to not rely on this logic, and catching runtime fields in comptime-only initializers, which has since been *correctly* fixed with better checks in `Sema.storePtr2`. That made the highly complex logic in `validateStructInit`, `validateUnionInit`, and `zirValidatePtrArrayInit` entirely redundant. Worse, it was also causing some tracked bugs, as well as a bug which I have identified and fixed in this PR (a corresponding behavior test is added). This commit simplifies union initialization by bringing the runtime logic more in line with the comptime logic: the tag is now always populated by `Sema.unionFieldPtr` based on `initializing`, where this previously happened only in the comptime case (with `validateUnionInit` instead handling it in the runtime case). Notably, this means that backends are now able to consider getting a pointer to an inactive union field as Illegal Behavior, because the `set_union_tag` instruction now appears *before* the `struct_field_ptr` instruction as you would probably expect it to. Resolves: #24520 Resolves: #24595
Diffstat (limited to 'test/behavior/array.zig')
-rw-r--r--test/behavior/array.zig14
1 files changed, 13 insertions, 1 deletions
diff --git a/test/behavior/array.zig b/test/behavior/array.zig
index 20c275382f..07eb632b1e 100644
--- a/test/behavior/array.zig
+++ b/test/behavior/array.zig
@@ -540,7 +540,6 @@ test "sentinel element count towards the ABI size calculation" {
}
test "zero-sized array with recursive type definition" {
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
@@ -1098,3 +1097,16 @@ test "initialize pointer to anyopaque with reference to empty array initializer"
// We can't check the value, but it's zero-bit, so the type matching is good enough.
comptime assert(@TypeOf(loaded) == @TypeOf(.{}));
}
+
+test "sentinel of runtime-known array initialization is populated" {
+ if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
+
+ var rt: u32 = undefined;
+ rt = 42;
+
+ const arr: [1:123]u32 = .{rt};
+ const elems: [*]const u32 = &arr;
+
+ try expect(elems[0] == 42);
+ try expect(elems[1] == 123);
+}