mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
Sema: make sentinel load through array pointer comptime known
This commit is contained in:
parent
1430ac2fbb
commit
99531b0d52
14
src/Sema.zig
14
src/Sema.zig
@ -25520,7 +25520,19 @@ fn elemVal(
|
||||
return block.addBinOp(.ptr_elem_val, indexable, elem_index);
|
||||
},
|
||||
.One => {
|
||||
assert(indexable_ty.childType(mod).zigTypeTag(mod) == .Array); // Guaranteed by checkIndexable
|
||||
const array_ty = indexable_ty.childType(mod); // Guaranteed by checkIndexable
|
||||
assert(array_ty.zigTypeTag(mod) == .Array);
|
||||
|
||||
if (array_ty.sentinel(mod)) |sentinel| {
|
||||
// index must be defined since it can access out of bounds
|
||||
if (try sema.resolveDefinedValue(block, elem_index_src, elem_index)) |index_val| {
|
||||
const index = @intCast(usize, index_val.toUnsignedInt(mod));
|
||||
if (index == array_ty.arrayLen(mod)) {
|
||||
return sema.addConstant(array_ty.childType(mod), sentinel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const elem_ptr = try sema.elemPtr(block, indexable_src, indexable, elem_index, elem_index_src, false, oob_safety);
|
||||
return sema.analyzeLoad(block, indexable_src, elem_ptr, elem_index_src);
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user