Преглед на файлове

Fix issue with printing invalid IR for nested unions
(GitHub #4)

Ginger Bill преди 8 години
родител
ревизия
0f809989e3
променени са 4 файла, в които са добавени 20 реда и са изтрити 9 реда
  1. 12 4
      code/demo.odin
  2. 2 0
      src/ssa.c
  3. 5 3
      src/ssa_opt.c
  4. 1 2
      src/ssa_print.c

+ 12 - 4
code/demo.odin

@@ -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 {
+	}
+};

+ 2 - 0
src/ssa.c

@@ -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));
 }
 

+ 5 - 3
src/ssa_opt.c

@@ -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;
-
-
 	}
 }
 

+ 1 - 2
src/ssa_print.c

@@ -206,7 +206,7 @@ void ssa_print_type(ssaFileBuffer *f, ssaModule *m, Type *t) {
 				}
 				Type *ft = t->Record.fields[i]->type;
 				Type *bft = base_type(ft);
-				if (!is_type_struct(bft)) {
+				if (!is_type_struct(bft) && !is_type_union(bft)) {
 					ft = bft;
 				}
 				ssa_print_type(f, m, ft);
@@ -242,7 +242,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));
 		}