Skip to content

Commit 05f78ad

Browse files
committed
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.
1 parent 644041b commit 05f78ad

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/Sema.zig

+7-2
Original file line numberDiff line numberDiff line change
@@ -29922,8 +29922,13 @@ fn beginComptimePtrMutation(
2992229922
// We might have a pointer to multiple elements of the array (e.g. a pointer
2992329923
// to a sub-array). In this case, we just have to reinterpret the relevant
2992429924
// bytes of the whole array rather than any single element.
29925-
const elem_abi_size_u64 = try sema.typeAbiSize(base_elem_ty);
29926-
if (elem_abi_size_u64 < try sema.typeAbiSize(ptr_elem_ty)) {
29925+
reinterp_multi_elem: {
29926+
if (try sema.typeRequiresComptime(base_elem_ty)) break :reinterp_multi_elem;
29927+
if (try sema.typeRequiresComptime(ptr_elem_ty)) break :reinterp_multi_elem;
29928+
29929+
const elem_abi_size_u64 = try sema.typeAbiSize(base_elem_ty);
29930+
if (elem_abi_size_u64 >= try sema.typeAbiSize(ptr_elem_ty)) break :reinterp_multi_elem;
29931+
2992729932
const elem_abi_size = try sema.usizeCast(block, src, elem_abi_size_u64);
2992829933
const elem_idx = try sema.usizeCast(block, src, elem_ptr.index);
2992929934
return .{

0 commit comments

Comments
 (0)