commit 05f78adeaf7685e6107da7c3533b233ce19a54b8 (tree)
parent 644041b3a492558592e1306d2214c9e6b25de53b
Author: mlugg <mlugg@mlugg.co.uk>
Date: Sat, 16 Sep 2023 13:10:56 +0100
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.
Diffstat:
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/Sema.zig b/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 .{