diff --git a/src/codegen.cpp b/src/codegen.cpp index e12f89756d07..98ee3c30f0d8 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -3873,9 +3873,6 @@ static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutable *executab TypeUnionField *field = instruction->field; - if (!type_has_bits(field->type_entry)) - return nullptr; - LLVMValueRef union_ptr = ir_llvm_value(g, instruction->union_ptr); LLVMTypeRef field_type_ref = LLVMPointerType(get_llvm_type(g, field->type_entry), 0); @@ -3908,6 +3905,9 @@ static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutable *executab LLVMPositionBuilderAtEnd(g->builder, ok_block); } + if (!type_has_bits(field->type_entry)) + return nullptr; + LLVMValueRef union_field_ptr = LLVMBuildStructGEP(g->builder, union_ptr, union_type->data.unionation.gen_union_index, ""); LLVMValueRef bitcasted_union_field_ptr = LLVMBuildBitCast(g->builder, union_field_ptr, field_type_ref, ""); diff --git a/src/ir.cpp b/src/ir.cpp index 32e3692afd0b..7fb8117c9670 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -15626,6 +15626,12 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source if (value == ira->codegen->invalid_instruction) return ira->codegen->invalid_instruction; + if (ptr->id == IrInstructionIdUnionFieldPtr && child_type->id == ZigTypeIdVoid) { + IrInstruction *result = ir_build_store_ptr(&ira->new_irb, source_instr->scope, source_instr->source_node, ptr, value); + result->value.type = ira->codegen->builtin_types.entry_void; + return result; + } + switch (type_has_one_possible_value(ira->codegen, child_type)) { case OnePossibleValueInvalid: return ira->codegen->invalid_instruction;