mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 14:23:09 +00:00
parent
af2ede4d96
commit
505b9db909
@ -7195,7 +7195,7 @@ check: switch (const_val->special) {
|
|||||||
union_value_ref = LLVMGetUndef(union_type_ref);
|
union_value_ref = LLVMGetUndef(union_type_ref);
|
||||||
make_unnamed_struct = false;
|
make_unnamed_struct = false;
|
||||||
} else {
|
} else {
|
||||||
uint64_t field_type_bytes = LLVMStoreSizeOfType(g->target_data_ref,
|
uint64_t field_type_bytes = LLVMABISizeOfType(g->target_data_ref,
|
||||||
get_llvm_type(g, payload_value->type));
|
get_llvm_type(g, payload_value->type));
|
||||||
uint64_t pad_bytes = type_entry->data.unionation.union_abi_size - field_type_bytes;
|
uint64_t pad_bytes = type_entry->data.unionation.union_abi_size - field_type_bytes;
|
||||||
LLVMValueRef correctly_typed_value = gen_const_val(g, payload_value, "");
|
LLVMValueRef correctly_typed_value = gen_const_val(g, payload_value, "");
|
||||||
@ -7235,7 +7235,7 @@ check: switch (const_val->special) {
|
|||||||
uint64_t last_field_offset = LLVMOffsetOfElement(g->target_data_ref, LLVMTypeOf(result), 1);
|
uint64_t last_field_offset = LLVMOffsetOfElement(g->target_data_ref, LLVMTypeOf(result), 1);
|
||||||
uint64_t end_offset = last_field_offset +
|
uint64_t end_offset = last_field_offset +
|
||||||
LLVMStoreSizeOfType(g->target_data_ref, LLVMTypeOf(fields[1]));
|
LLVMStoreSizeOfType(g->target_data_ref, LLVMTypeOf(fields[1]));
|
||||||
uint64_t expected_sz = LLVMStoreSizeOfType(g->target_data_ref, get_llvm_type(g, type_entry));
|
uint64_t expected_sz = LLVMABISizeOfType(g->target_data_ref, get_llvm_type(g, type_entry));
|
||||||
unsigned pad_sz = expected_sz - end_offset;
|
unsigned pad_sz = expected_sz - end_offset;
|
||||||
if (pad_sz != 0) {
|
if (pad_sz != 0) {
|
||||||
fields[2] = LLVMGetUndef(LLVMArrayType(LLVMInt8Type(), pad_sz));
|
fields[2] = LLVMGetUndef(LLVMArrayType(LLVMInt8Type(), pad_sz));
|
||||||
|
|||||||
@ -620,3 +620,12 @@ test "0-sized extern union definition" {
|
|||||||
|
|
||||||
expect(U.f == 1);
|
expect(U.f == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "union initializer generates padding only if needed" {
|
||||||
|
const U = union(enum) {
|
||||||
|
A: u24,
|
||||||
|
};
|
||||||
|
|
||||||
|
var v = U{ .A = 532 };
|
||||||
|
expect(v.A == 532);
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user