Commit 05f78adeaf

mlugg <mlugg@mlugg.co.uk>
2023-09-16 14:10:56
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
Changed files (1)
src/Sema.zig
@@ -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 .{