x86_64: fix global pointers to packed struct fields

This commit is contained in:
Jacob Young
2023-06-25 00:43:18 -04:00
parent 9d0b8a27b6
commit 5b74278510
3 changed files with 16 additions and 7 deletions

View File

@@ -684,10 +684,22 @@ fn lowerParentPtr(
.struct_type,
.anon_struct_type,
.union_type,
=> @as(u32, @intCast(base_type.toType().structFieldOffset(
@as(u32, @intCast(field.index)),
mod,
))),
=> switch (base_type.toType().containerLayout(mod)) {
.Auto, .Extern => @intCast(base_type.toType().structFieldOffset(
@intCast(field.index),
mod,
)),
.Packed => if (mod.typeToStruct(base_type.toType())) |struct_obj|
math.divExact(u16, struct_obj.packedFieldBitOffset(
mod,
@intCast(field.index),
), 8) catch |err| switch (err) {
error.UnexpectedRemainder => 0,
error.DivisionByZero => unreachable,
}
else
0,
},
else => unreachable,
}),
);