| author | |
| committer | |
| log | 7f9e841f746bb3eaf6ac205092a30bc7ed12a068 |
| tree | 14b168089558d7c1c27a0ea2f6f69b8d1fbc1813 |
| parent | 59dad43de26a89ca72a97224a171d724dcc6ee41 |
Closes #133083 files changed, 24 insertions(+), 12 deletions(-)
src/Sema.zig+2-10| ... | ... | @@ -16825,7 +16825,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 16825 | 16825 | const bitoffset_src: LazySrcLoc = .{ .node_offset_ptr_bitoffset = extra.data.src_node }; |
| 16826 | 16826 | const hostsize_src: LazySrcLoc = .{ .node_offset_ptr_hostsize = extra.data.src_node }; |
| 16827 | 16827 | |
| 16828 | const unresolved_elem_ty = blk: { | |
| 16828 | const elem_ty = blk: { | |
| 16829 | 16829 | const air_inst = try sema.resolveInst(extra.data.elem_type); |
| 16830 | 16830 | const ty = sema.analyzeAsType(block, elem_ty_src, air_inst) catch |err| { |
| 16831 | 16831 | if (err == error.AnalysisFail and sema.err != null and sema.typeOf(air_inst).isSinglePointer()) { |
| ... | ... | @@ -16854,7 +16854,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 16854 | 16854 | // Check if this happens to be the lazy alignment of our element type, in |
| 16855 | 16855 | // which case we can make this 0 without resolving it. |
| 16856 | 16856 | if (val.castTag(.lazy_align)) |payload| { |
| 16857 | if (payload.data.eql(unresolved_elem_ty, sema.mod)) { | |
| 16857 | if (payload.data.eql(elem_ty, sema.mod)) { | |
| 16858 | 16858 | break :blk 0; |
| 16859 | 16859 | } |
| 16860 | 16860 | } |
| ... | ... | @@ -16887,14 +16887,6 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 16887 | 16887 | return sema.fail(block, bitoffset_src, "bit offset starts after end of host integer", .{}); |
| 16888 | 16888 | } |
| 16889 | 16889 | |
| 16890 | const elem_ty = if (abi_align == 0) | |
| 16891 | unresolved_elem_ty | |
| 16892 | else t: { | |
| 16893 | const elem_ty = try sema.resolveTypeFields(unresolved_elem_ty); | |
| 16894 | try sema.resolveTypeLayout(elem_ty); | |
| 16895 | break :t elem_ty; | |
| 16896 | }; | |
| 16897 | ||
| 16898 | 16890 | if (elem_ty.zigTypeTag() == .NoReturn) { |
| 16899 | 16891 | return sema.fail(block, elem_ty_src, "pointer to noreturn not allowed", .{}); |
| 16900 | 16892 | } else if (elem_ty.zigTypeTag() == .Fn) { |
src/type.zig+10-2| ... | ... | @@ -6491,8 +6491,16 @@ pub const Type = extern union { |
| 6491 | 6491 | // type, we change it to 0 here. If this causes an assertion trip because the |
| 6492 | 6492 | // pointee type needs to be resolved more, that needs to be done before calling |
| 6493 | 6493 | // this ptr() function. |
| 6494 | if (d.@"align" != 0 and d.@"align" == d.pointee_type.abiAlignment(target)) { | |
| 6495 | d.@"align" = 0; | |
| 6494 | if (d.@"align" != 0) canonicalize: { | |
| 6495 | if (d.pointee_type.castTag(.@"struct")) |struct_ty| { | |
| 6496 | if (!struct_ty.data.haveLayout()) break :canonicalize; | |
| 6497 | } | |
| 6498 | if (d.pointee_type.cast(Payload.Union)) |union_ty| { | |
| 6499 | if (!union_ty.data.haveLayout()) break :canonicalize; | |
| 6500 | } | |
| 6501 | if (d.@"align" == d.pointee_type.abiAlignment(target)) { | |
| 6502 | d.@"align" = 0; | |
| 6503 | } | |
| 6496 | 6504 | } |
| 6497 | 6505 | |
| 6498 | 6506 | // Canonicalize host_size. If it matches the bit size of the pointee type, |
test/behavior/struct.zig+12| ... | ... | @@ -1406,3 +1406,15 @@ test "address of zero-bit field is equal to address of only field" { |
| 1406 | 1406 | try std.testing.expectEqual(&a, a_ptr); |
| 1407 | 1407 | } |
| 1408 | 1408 | } |
| 1409 | ||
| 1410 | test "struct field has a pointer to an aligned version of itself" { | |
| 1411 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | |
| 1412 | ||
| 1413 | const E = struct { | |
| 1414 | next: *align(1) @This(), | |
| 1415 | }; | |
| 1416 | var e: E = undefined; | |
| 1417 | e = .{ .next = &e }; | |
| 1418 | ||
| 1419 | try expect(&e == e.next); | |
| 1420 | } |