aboutsummaryrefslogtreecommitdiff
path: root/src/Type.zig
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2025-06-03 00:47:33 -0400
committerAndrew Kelley <andrew@ziglang.org>2025-06-03 15:04:43 -0400
commit80170d017b59950d4e8e8bd6da7c3c3b80b0730b (patch)
tree514a1f0f805cc74f56c43ff410e26a1873738f2a /src/Type.zig
parent597dd328e3a66a6245320121843933e9436183c5 (diff)
downloadzig-80170d017b59950d4e8e8bd6da7c3c3b80b0730b.tar.gz
zig-80170d017b59950d4e8e8bd6da7c3c3b80b0730b.zip
Legalize: handle packed semantics
Closes #22915
Diffstat (limited to 'src/Type.zig')
-rw-r--r--src/Type.zig34
1 files changed, 24 insertions, 10 deletions
diff --git a/src/Type.zig b/src/Type.zig
index a1b64a17fa..995ee4992e 100644
--- a/src/Type.zig
+++ b/src/Type.zig
@@ -1636,14 +1636,22 @@ pub fn bitSizeInner(
.array_type => |array_type| {
const len = array_type.lenIncludingSentinel();
if (len == 0) return 0;
- const elem_ty = Type.fromInterned(array_type.child);
- const elem_size = (try elem_ty.abiSizeInner(strat_lazy, zcu, tid)).scalar;
- if (elem_size == 0) return 0;
- const elem_bit_size = try elem_ty.bitSizeInner(strat, zcu, tid);
- return (len - 1) * 8 * elem_size + elem_bit_size;
+ const elem_ty: Type = .fromInterned(array_type.child);
+ switch (zcu.comp.getZigBackend()) {
+ else => {
+ const elem_size = (try elem_ty.abiSizeInner(strat_lazy, zcu, tid)).scalar;
+ if (elem_size == 0) return 0;
+ const elem_bit_size = try elem_ty.bitSizeInner(strat, zcu, tid);
+ return (len - 1) * 8 * elem_size + elem_bit_size;
+ },
+ .stage2_x86_64 => {
+ const elem_bit_size = try elem_ty.bitSizeInner(strat, zcu, tid);
+ return elem_bit_size * len;
+ },
+ }
},
.vector_type => |vector_type| {
- const child_ty = Type.fromInterned(vector_type.child);
+ const child_ty: Type = .fromInterned(vector_type.child);
const elem_bit_size = try child_ty.bitSizeInner(strat, zcu, tid);
return elem_bit_size * vector_type.len;
},
@@ -3549,10 +3557,16 @@ pub fn packedStructFieldPtrInfo(struct_ty: Type, parent_ptr_ty: Type, field_idx:
running_bits += @intCast(f_ty.bitSize(zcu));
}
- const res_host_size: u16, const res_bit_offset: u16 = if (parent_ptr_info.packed_offset.host_size != 0)
- .{ parent_ptr_info.packed_offset.host_size, parent_ptr_info.packed_offset.bit_offset + bit_offset }
- else
- .{ (running_bits + 7) / 8, bit_offset };
+ const res_host_size: u16, const res_bit_offset: u16 = if (parent_ptr_info.packed_offset.host_size != 0) .{
+ parent_ptr_info.packed_offset.host_size,
+ parent_ptr_info.packed_offset.bit_offset + bit_offset,
+ } else .{
+ switch (zcu.comp.getZigBackend()) {
+ else => (running_bits + 7) / 8,
+ .stage2_x86_64 => @intCast(struct_ty.abiSize(zcu)),
+ },
+ bit_offset,
+ };
// If the field happens to be byte-aligned, simplify the pointer type.
// We can only do this if the pointee's bit size matches its ABI byte size,