aboutsummaryrefslogtreecommitdiff
path: root/src/arch/x86_64/CodeGen.zig
diff options
context:
space:
mode:
authorXavier Bouchoux <xavierb@gmail.com>2023-07-29 11:50:25 +0200
committerXavier Bouchoux <xavierb@gmail.com>2023-07-29 18:16:13 +0200
commit8c367ef99aae05ddba800a6c01cb07677e2f512c (patch)
treea9fecf3efe8e4ed6285f4de7d11ad02edb86e3d1 /src/arch/x86_64/CodeGen.zig
parent46abf2045476a32b6f4dd939679c0fbc7a639133 (diff)
downloadzig-8c367ef99aae05ddba800a6c01cb07677e2f512c.tar.gz
zig-8c367ef99aae05ddba800a6c01cb07677e2f512c.zip
codegen: fix access to byte-aligned nested packed struct elems
When acessing a packed struct member via a byte aligned ptr (from the optimisation in Sema.structFieldPtrByIndex()) the codegen must apply the parent ptr packed_offset in addition to the field offset itself. resolves https://github.com/ziglang/zig/issues/16609
Diffstat (limited to 'src/arch/x86_64/CodeGen.zig')
-rw-r--r--src/arch/x86_64/CodeGen.zig4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/arch/x86_64/CodeGen.zig b/src/arch/x86_64/CodeGen.zig
index 76e63675a1..fb4c8a5745 100644
--- a/src/arch/x86_64/CodeGen.zig
+++ b/src/arch/x86_64/CodeGen.zig
@@ -5556,12 +5556,14 @@ fn fieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, index: u32
const mod = self.bin_file.options.module.?;
const ptr_field_ty = self.typeOfIndex(inst);
const ptr_container_ty = self.typeOf(operand);
+ const ptr_container_ty_info = ptr_container_ty.ptrInfo(mod);
const container_ty = ptr_container_ty.childType(mod);
+
const field_offset: i32 = @intCast(switch (container_ty.containerLayout(mod)) {
.Auto, .Extern => container_ty.structFieldOffset(index, mod),
.Packed => if (container_ty.zigTypeTag(mod) == .Struct and
ptr_field_ty.ptrInfo(mod).packed_offset.host_size == 0)
- container_ty.packedStructFieldByteOffset(index, mod)
+ container_ty.packedStructFieldByteOffset(index, mod) + @divExact(ptr_container_ty_info.packed_offset.bit_offset, 8)
else
0,
});