Sema: don't attempt to reinterpret comptime-only types when mutating comptime memory

I have no idea how correct this code is, but I'm working on a full
rewrite of this logic anyway, and this certainly seems more correct than
before.
This commit is contained in:
mlugg 2023-09-16 13:10:56 +01:00 committed by Matthew Lugg
parent 644041b3a4
commit 05f78adeaf

View File

@ -29922,8 +29922,13 @@ fn beginComptimePtrMutation(
// We might have a pointer to multiple elements of the array (e.g. a pointer
// to a sub-array). In this case, we just have to reinterpret the relevant
// bytes of the whole array rather than any single element.
const elem_abi_size_u64 = try sema.typeAbiSize(base_elem_ty);
if (elem_abi_size_u64 < try sema.typeAbiSize(ptr_elem_ty)) {
reinterp_multi_elem: {
if (try sema.typeRequiresComptime(base_elem_ty)) break :reinterp_multi_elem;
if (try sema.typeRequiresComptime(ptr_elem_ty)) break :reinterp_multi_elem;
const elem_abi_size_u64 = try sema.typeAbiSize(base_elem_ty);
if (elem_abi_size_u64 >= try sema.typeAbiSize(ptr_elem_ty)) break :reinterp_multi_elem;
const elem_abi_size = try sema.usizeCast(block, src, elem_abi_size_u64);
const elem_idx = try sema.usizeCast(block, src, elem_ptr.index);
return .{