aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/pointers.zig
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2025-04-02 06:37:41 +0100
committerMatthew Lugg <mlugg@mlugg.co.uk>2025-04-28 19:43:58 +0100
commitd038676a1f46ecab2bd095d3503ab05bcd8de58c (patch)
tree8525291c4a2fd35e61299ab2d0a19b8a110f6196 /test/behavior/pointers.zig
parent365ed0ed68b6f6c39b3b8f5373fbba25fe09a518 (diff)
downloadzig-d038676a1f46ecab2bd095d3503ab05bcd8de58c.tar.gz
zig-d038676a1f46ecab2bd095d3503ab05bcd8de58c.zip
Sema: fix a few indexing bugs
* Indexing zero-bit types should not produce AIR indexing instructions * Getting a runtime-known element pointer from a many-pointer should check that the many-pointer is not comptime-only Resolves: #23405
Diffstat (limited to 'test/behavior/pointers.zig')
-rw-r--r--test/behavior/pointers.zig24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/behavior/pointers.zig b/test/behavior/pointers.zig
index e892918571..b8f81d74af 100644
--- a/test/behavior/pointers.zig
+++ b/test/behavior/pointers.zig
@@ -760,3 +760,27 @@ test "comptime pointer equality through distinct elements with well-defined layo
comptime assert(buf[1] == 456);
comptime assert(second_elem.* == 456);
}
+
+test "pointers to elements of slice of zero-bit type" {
+ if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
+
+ var slice: []const u0 = undefined;
+ slice = &.{ 0, 0 };
+
+ const a = &slice[0];
+ const b = &slice[1];
+
+ try expect(a == b);
+}
+
+test "pointers to elements of many-ptr to zero-bit type" {
+ if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
+
+ var many_ptr: [*]const u0 = undefined;
+ many_ptr = &.{ 0, 0 };
+
+ const a = &many_ptr[0];
+ const b = &many_ptr[1];
+
+ try expect(a == b);
+}