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
This commit is contained in:
mlugg
2025-04-02 06:37:41 +01:00
committed by Matthew Lugg
parent 365ed0ed68
commit d038676a1f
3 changed files with 47 additions and 0 deletions

View File

@@ -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);
}