File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -7195,7 +7195,7 @@ check: switch (const_val->special) {
7195
7195
union_value_ref = LLVMGetUndef (union_type_ref);
7196
7196
make_unnamed_struct = false ;
7197
7197
} else {
7198
- uint64_t field_type_bytes = LLVMStoreSizeOfType (g->target_data_ref ,
7198
+ uint64_t field_type_bytes = LLVMABISizeOfType (g->target_data_ref ,
7199
7199
get_llvm_type (g, payload_value->type ));
7200
7200
uint64_t pad_bytes = type_entry->data .unionation .union_abi_size - field_type_bytes;
7201
7201
LLVMValueRef correctly_typed_value = gen_const_val (g, payload_value, " " );
@@ -7235,7 +7235,7 @@ check: switch (const_val->special) {
7235
7235
uint64_t last_field_offset = LLVMOffsetOfElement (g->target_data_ref , LLVMTypeOf (result), 1 );
7236
7236
uint64_t end_offset = last_field_offset +
7237
7237
LLVMStoreSizeOfType (g->target_data_ref , LLVMTypeOf (fields[1 ]));
7238
- uint64_t expected_sz = LLVMStoreSizeOfType (g->target_data_ref , get_llvm_type (g, type_entry));
7238
+ uint64_t expected_sz = LLVMABISizeOfType (g->target_data_ref , get_llvm_type (g, type_entry));
7239
7239
unsigned pad_sz = expected_sz - end_offset;
7240
7240
if (pad_sz != 0 ) {
7241
7241
fields[2 ] = LLVMGetUndef (LLVMArrayType (LLVMInt8Type (), pad_sz));
Original file line number Diff line number Diff line change @@ -620,3 +620,12 @@ test "0-sized extern union definition" {
620
620
621
621
expect (U .f == 1 );
622
622
}
623
+
624
+ test "union initializer generates padding only if needed" {
625
+ const U = union (enum ) {
626
+ A : u24 ,
627
+ };
628
+
629
+ var v = U { .A = 532 };
630
+ expect (v .A == 532 );
631
+ }
You can’t perform that action at this time.
0 commit comments