authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2022-10-15 03:31:17-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-10-15 14:19:40-04:00
logf9192adaba0eb344ed12aad9c675cd73b740d2a2
treef06afc534fa97ca50c1e8d56189d5697d160b095
parentc7f98332383d71a57699426027e82c435e91addc

llvm: fix lowering of non-byte-aligned field pointers

* When a field starts at some bit offset within a byte you need to load starting from that byte and shift, not starting from the next byte, so a rounded-down divide is required here, not a rounded-up one. * Remove paragraph from doc that no longer relates to anything. Closes #12363

2 files changed, 1 insertions(+), 6 deletions(-)

doc/langref.html.in-5
......@@ -3341,7 +3341,6 @@ fn doTheTest() !void {
33413341 Zig allows the address to be taken of a non-byte-aligned field:
33423342 </p>
33433343 {#code_begin|test|pointer_to_non-byte_aligned_field#}
3344 {#backend_stage1#}
33453344const std = @import("std");
33463345const expect = std.testing.expect;
33473346
......@@ -3398,7 +3397,6 @@ fn bar(x: *const u3) u3 {
33983397 Pointers to non-ABI-aligned fields share the same address as the other fields within their host integer:
33993398 </p>
34003399 {#code_begin|test|packed_struct_field_addrs#}
3401 {#backend_stage1#}
34023400const std = @import("std");
34033401const expect = std.testing.expect;
34043402
......@@ -3463,9 +3461,6 @@ test "overaligned pointer to packed struct" {
34633461 try expect(ptr_to_b.* == 2);
34643462}
34653463 {#code_end#}
3466 <p>When this bug is fixed, the above test in the documentation will unexpectedly pass, which will
3467 cause the test suite to fail, notifying the bug fixer to update these docs.
3468 </p>
34693464 <p>
34703465 It's also possible to set alignment of struct fields:
34713466 </p>
src/codegen/llvm.zig+1-1
......@@ -3943,7 +3943,7 @@ pub const DeclGen = struct {
39433943 }
39443944 break :b b;
39453945 };
3946 const byte_offset = llvm_usize.constInt((prev_bits + 7) / 8, .False);
3946 const byte_offset = llvm_usize.constInt(prev_bits / 8, .False);
39473947 const field_addr = base_addr.constAdd(byte_offset);
39483948 bitcast_needed = false;
39493949 const final_llvm_ty = (try dg.lowerType(ptr_child_ty)).pointerType(0);