| author | |
| committer | |
| log | 67bd0267db00cf71b5f3301559a39bac32b65476 |
| tree | 0833d087464e2a0ea5635b066dc24b6983966e10 |
| parent | 70e934f116f3b889fcee755380a708fdceaaf699 |
| signature |
Make sure the resulting type is in-sync with the one produced and used
by LLVM.
Fixes #31382 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,7 +7839,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS |
| 7839 | 7839 | ||
| 7840 | assert(next_offset >= llvm_next_offset); | 7840 | assert(next_offset >= llvm_next_offset); |
| 7841 | if (next_offset > llvm_next_offset) { | 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 - llvm_next_offset; |
| 7843 | if (pad_bytes != 0) { | 7843 | if (pad_bytes != 0) { |
| 7844 | LLVMTypeRef pad_llvm_type = LLVMArrayType(LLVMInt8Type(), pad_bytes); | 7844 | LLVMTypeRef pad_llvm_type = LLVMArrayType(LLVMInt8Type(), pad_bytes); |
| 7845 | element_types[gen_field_index] = pad_llvm_type; | 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,3 +670,22 @@ test "packed struct with non-ABI-aligned field" { |
| 670 | expect(s.x == 1); | 670 | expect(s.x == 1); |
| 671 | expect(s.y == 42); | 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 | } |