| author | |
| committer | |
| log | 878aece87b11e112b2ab890aa5242d8c472864a5 |
| tree | ff44a060d3fc463f1d024b30cfb0b763123381d0 |
| parent | 70e934f116f3b889fcee755380a708fdceaaf699 |
| parent | 09575bc0d605ca59bba19e98b66d0d0b1ba4fa89 |
| signature |
closes #32132 files changed, 20 insertions(+), 1 deletions(-)
src/analyze.cpp+1-1| ... | ... | @@ -7839,7 +7839,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS |
| 7839 | 7839 | |
| 7840 | 7840 | assert(next_offset >= llvm_next_offset); |
| 7841 | 7841 | if (next_offset > llvm_next_offset) { |
| 7842 | size_t pad_bytes = next_offset - (field->offset + field_type->abi_size); | |
| 7842 | size_t pad_bytes = next_offset - (field->offset + LLVMStoreSizeOfType(g->target_data_ref, llvm_type)); | |
| 7843 | 7843 | if (pad_bytes != 0) { |
| 7844 | 7844 | LLVMTypeRef pad_llvm_type = LLVMArrayType(LLVMInt8Type(), pad_bytes); |
| 7845 | 7845 | element_types[gen_field_index] = pad_llvm_type; |
test/stage1/behavior/struct.zig+19| ... | ... | @@ -670,3 +670,22 @@ test "packed struct with non-ABI-aligned field" { |
| 670 | 670 | expect(s.x == 1); |
| 671 | 671 | expect(s.y == 42); |
| 672 | 672 | } |
| 673 | ||
| 674 | test "non-packed struct with u128 entry in union" { | |
| 675 | const U = union(enum) { | |
| 676 | Num: u128, | |
| 677 | Void, | |
| 678 | }; | |
| 679 | ||
| 680 | const S = struct { | |
| 681 | f1: U, | |
| 682 | f2: U, | |
| 683 | }; | |
| 684 | ||
| 685 | var sx: S = undefined; | |
| 686 | var s = &sx; | |
| 687 | std.testing.expect(@ptrToInt(&s.f2) - @ptrToInt(&s.f1) == @byteOffsetOf(S, "f2")); | |
| 688 | var v2 = U{ .Num = 123 }; | |
| 689 | s.f2 = v2; | |
| 690 | std.testing.expect(s.f2.Num == 123); | |
| 691 | } |