Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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, "");
Expand Down
6 changes: 6 additions & 0 deletions src/ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down