diff options
| author | gingerBill <bill@gingerbill.org> | 2023-06-26 17:36:27 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2023-06-26 17:36:27 +0100 |
| commit | 8b8310711e4924678e605278fca1f8dbf517b903 (patch) | |
| tree | 7e242ed95488b534f99c61d8d8084b60e29347cc /src | |
| parent | cdcb64b0d08be85c3ea579270eeb4d193b4cb495 (diff) | |
Fix #2594 zero sized union code generation
Diffstat (limited to 'src')
| -rw-r--r-- | src/llvm_backend.cpp | 4 | ||||
| -rw-r--r-- | src/llvm_backend_general.cpp | 1 | ||||
| -rw-r--r-- | src/llvm_backend_type.cpp | 5 |
3 files changed, 6 insertions, 4 deletions
diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index 730610ad9..12abe7b16 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -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); diff --git a/src/llvm_backend_general.cpp b/src/llvm_backend_general.cpp index 9333f13a4..017eeca2e 100644 --- a/src/llvm_backend_general.cpp +++ b/src/llvm_backend_general.cpp @@ -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! diff --git a/src/llvm_backend_type.cpp b/src/llvm_backend_type.cpp index a54fde748..4716733cc 100644 --- a/src/llvm_backend_type.cpp +++ b/src/llvm_backend_type.cpp @@ -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 { |