Fix issue with printing invalid IR for nested unions

(GitHub #4)
This commit is contained in:
Ginger Bill
2016-12-17 10:22:38 +00:00
parent d4457e9fa4
commit 625b98eac4
4 changed files with 20 additions and 14 deletions

View File

@@ -1,6 +1,14 @@
#import "fmt.odin";
#import "sync.odin";
Test1 :: type union {
A: int;
B: int;
};
Test :: type struct {
a: Test1;
};
main :: proc() {
fmt.println("Hellope");
}
test: Test;
match type x : ^test.a {
}
};

View File

@@ -1579,12 +1579,14 @@ ssaValue *ssa_emit_union_tag_ptr(ssaProcedure *proc, ssaValue *u) {
Type *t = ssa_type(u);
GB_ASSERT(is_type_pointer(t) &&
is_type_union(type_deref(t)));
GB_ASSERT(are_types_identical(t, ssa_type(u)));
return ssa_emit(proc, ssa_make_instr_union_tag_ptr(proc, u));
}
ssaValue *ssa_emit_union_tag_value(ssaProcedure *proc, ssaValue *u) {
Type *t = ssa_type(u);
GB_ASSERT(is_type_union(t));
GB_ASSERT(are_types_identical(t, ssa_type(u)));
return ssa_emit(proc, ssa_make_instr_union_tag_value(proc, u));
}

View File

@@ -54,7 +54,11 @@ void ssa_opt_add_operands(ssaValueArray *ops, ssaInstr *i) {
array_add(ops, i->Phi.edges.e[j]);
}
break;
case ssaInstr_Unreachable: break;
case ssaInstr_Unreachable:
break;
case ssaInstr_UnaryOp:
array_add(ops, i->UnaryOp.expr);
break;
case ssaInstr_BinaryOp:
array_add(ops, i->BinaryOp.left);
array_add(ops, i->BinaryOp.right);
@@ -88,8 +92,6 @@ void ssa_opt_add_operands(ssaValueArray *ops, ssaInstr *i) {
array_add(ops, i->SliceBoundsCheck.high);
array_add(ops, i->SliceBoundsCheck.max);
break;
}
}

View File

@@ -204,12 +204,7 @@ void ssa_print_type(ssaFileBuffer *f, ssaModule *m, Type *t) {
if (i > 0) {
ssa_fprintf(f, ", ");
}
Type *ft = t->Record.fields[i]->type;
Type *bft = base_type(ft);
if (!is_type_struct(bft)) {
ft = bft;
}
ssa_print_type(f, m, ft);
ssa_print_type(f, m, t->Record.fields[i]->type);
}
ssa_fprintf(f, "}");
if (t->Record.struct_is_packed) {
@@ -242,7 +237,6 @@ void ssa_print_type(ssaFileBuffer *f, ssaModule *m, Type *t) {
String *name = map_string_get(&m->type_names, hash_pointer(t));
GB_ASSERT_MSG(name != NULL, "%.*s", LIT(t->Named.name));
ssa_print_encoded_local(f, *name);
// ssa_print_encoded_local(f, t->Named.name);
} else {
ssa_print_type(f, m, base_type(t));
}