Fix #2594 zero sized union code generation

This commit is contained in:
gingerBill
2023-06-26 17:36:27 +01:00
parent cdcb64b0d0
commit 8b8310711e
3 changed files with 6 additions and 4 deletions
+3 -1
View File
@@ -218,7 +218,9 @@ gb_internal lbValue lb_equal_proc_for_type(lbModule *m, Type *type) {
LLVMBuildRet(p->builder, LLVMConstInt(lb_type(m, t_bool), 0, false));
} else if (type->kind == Type_Union) {
if (is_type_union_maybe_pointer(type)) {
if (type_size_of(type) == 0) {
LLVMBuildRet(p->builder, LLVMConstInt(lb_type(m, t_bool), 1, false));
} else if (is_type_union_maybe_pointer(type)) {
Type *v = type->Union.variants[0];
Type *pv = alloc_type_pointer(v);
+1
View File
@@ -1323,6 +1323,7 @@ gb_internal lbValue lb_emit_union_tag_value(lbProcedure *p, lbValue u) {
gb_internal void lb_emit_store_union_variant_tag(lbProcedure *p, lbValue parent, Type *variant_type) {
Type *t = type_deref(parent.type);
GB_ASSERT(is_type_union(t));
if (is_type_union_maybe_pointer(t) || type_size_of(t) == 0) {
// No tag needed!
+2 -3
View File
@@ -654,10 +654,9 @@ gb_internal void lb_setup_type_info_data(lbProcedure *p) { // NOTE(bill): Setup
lbValue count = lb_const_int(m, t_int, variant_count);
vals[0] = llvm_const_slice(m, memory_types, count);
i64 tag_size = union_tag_size(t);
i64 tag_offset = align_formula(t->Union.variant_block_size, tag_size);
i64 tag_size = union_tag_size(t);
if (tag_size > 0) {
i64 tag_offset = align_formula(t->Union.variant_block_size, tag_size);
vals[1] = lb_const_int(m, t_uintptr, tag_offset).value;
vals[2] = lb_type_info(m, union_tag_type(t)).value;
} else {