authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-09-27 15:58:39-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-09-27 15:58:39-04:00
log878aece87b11e112b2ab890aa5242d8c472864a5
treeff44a060d3fc463f1d024b30cfb0b763123381d0
parent70e934f116f3b889fcee755380a708fdceaaf699
parent09575bc0d605ca59bba19e98b66d0d0b1ba4fa89
signaturelock-open Commit is signed but in an unrecognized format.

Merge branch 'LemonBoy-fix-3138'

closes #3213

2 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
78397839
78407840 assert(next_offset >= llvm_next_offset);
78417841 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));
78437843 if (pad_bytes != 0) {
78447844 LLVMTypeRef pad_llvm_type = LLVMArrayType(LLVMInt8Type(), pad_bytes);
78457845 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" {
670670 expect(s.x == 1);
671671 expect(s.y == 42);
672672}
673
674test "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}