Hack: union compound literal fix

This commit is contained in:
gingerBill
2018-11-29 22:23:30 +00:00
parent 3aec78b1d4
commit f3a4904f21
2 changed files with 13 additions and 5 deletions
+1 -1
View File
@@ -982,7 +982,7 @@ typedef struct gbThread {
gbSemaphore semaphore;
isize stack_size;
b32 is_running;
b32 volatile is_running;
} gbThread;
GB_DEF void gb_thread_init (gbThread *t);
+12 -4
View File
@@ -4330,7 +4330,6 @@ void ir_emit_store_union_variant(irProcedure *proc, irValue *parent, irValue *va
gbAllocator a = ir_allocator();
irValue *underlying = ir_emit_conv(proc, parent, alloc_type_pointer(variant_type));
irValue *v = variant;
ir_emit_store(proc, underlying, variant);
Type *t = type_deref(ir_type(parent));
@@ -7026,9 +7025,18 @@ irAddr ir_build_addr(irProcedure *proc, Ast *expr) {
GB_ASSERT(ir_type(field_expr)->kind != Type_Tuple);
irValue *fv = ir_emit_conv(proc, field_expr, ft);
irValue *gep = ir_emit_struct_ep(proc, v, cast(i32)index);
ir_emit_store(proc, gep, fv);
Type *fet = ir_type(field_expr);
// HACK TODO(bill): THIS IS A MASSIVE HACK!!!!
if (is_type_union(ft) && !are_types_identical(fet, ft)) {
GB_ASSERT(union_variant_index(ft, fet) > 0);
irValue *gep = ir_emit_struct_ep(proc, v, cast(i32)index);
ir_emit_store_union_variant(proc, gep, field_expr, fet);
} else {
irValue *fv = ir_emit_conv(proc, field_expr, ft);
irValue *gep = ir_emit_struct_ep(proc, v, cast(i32)index);
ir_emit_store(proc, gep, fv);
}
}
}
break;