diff options
| author | Xavier Bouchoux <xavierb@gmail.com> | 2023-07-29 11:50:25 +0200 |
|---|---|---|
| committer | Xavier Bouchoux <xavierb@gmail.com> | 2023-07-29 18:16:13 +0200 |
| commit | 8c367ef99aae05ddba800a6c01cb07677e2f512c (patch) | |
| tree | a9fecf3efe8e4ed6285f4de7d11ad02edb86e3d1 /src/codegen/llvm.zig | |
| parent | 46abf2045476a32b6f4dd939679c0fbc7a639133 (diff) | |
| download | zig-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/codegen/llvm.zig')
| -rw-r--r-- | src/codegen/llvm.zig | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 4af42bfa9b..129a769007 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -10611,6 +10611,7 @@ pub const FuncGen = struct { .Packed => { const result_ty = self.typeOfIndex(inst); const result_ty_info = result_ty.ptrInfo(mod); + const struct_ptr_ty_info = struct_ptr_ty.ptrInfo(mod); if (result_ty_info.packed_offset.host_size != 0) { // From LLVM's perspective, a pointer to a packed struct and a pointer @@ -10622,7 +10623,7 @@ pub const FuncGen = struct { // We have a pointer to a packed struct field that happens to be byte-aligned. // Offset our operand pointer by the correct number of bytes. - const byte_offset = struct_ty.packedStructFieldByteOffset(field_index, mod); + const byte_offset = struct_ty.packedStructFieldByteOffset(field_index, mod) + @divExact(struct_ptr_ty_info.packed_offset.bit_offset, 8); if (byte_offset == 0) return struct_ptr; const usize_ty = try o.lowerType(Type.usize); const llvm_index = try o.builder.intValue(usize_ty, byte_offset); |
