From 05f78adeaf7685e6107da7c3533b233ce19a54b8 Mon Sep 17 00:00:00 2001 From: mlugg Date: Sat, 16 Sep 2023 13:10:56 +0100 Subject: [PATCH] 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. --- src/Sema.zig | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Sema.zig b/src/Sema.zig index 458fd5786b..0421ee89da 100644 --- 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 .{