Browse Source

Fix String causes a crash when used in a polymorphic type #483

gingerBill 5 years ago
parent
commit
e01d8a04a9
2 changed files with 19 additions and 3 deletions
  1. 16 2
      src/ir_print.cpp
  2. 3 1
      src/types.cpp

+ 16 - 2
src/ir_print.cpp

@@ -669,7 +669,21 @@ void ir_print_exact_value(irFileBuffer *f, irModule *m, ExactValue value, Type *
 	value = convert_exact_value_for_type(value, type);
 
 	// NOTE(bill): Is this correct? Does this handle all cases regarding arrays?
-	if (is_type_array(type) &&
+	if (is_type_array(type) && value.kind == ExactValue_String && !is_type_u8(core_array_type(type))) {
+		i64 count  = type->Array.count;
+		Type *elem = type->Array.elem;
+		ir_write_byte(f, '[');
+
+		for (i64 i = 0; i < count; i++) {
+			if (i > 0) ir_write_str_lit(f, ", ");
+			ir_print_type(f, m, elem);
+			ir_write_byte(f, ' ');
+			ir_print_exact_value(f, m, value, elem);
+		}
+
+		ir_write_byte(f, ']');
+		return;
+	} else if (is_type_array(type) &&
 	    value.kind != ExactValue_Invalid &&
 	    value.kind != ExactValue_String &&
 	    value.kind != ExactValue_Compound) {
@@ -734,7 +748,7 @@ void ir_print_exact_value(irFileBuffer *f, irModule *m, ExactValue value, Type *
 			ir_write_str_lit(f, ", ");
 			ir_print_type(f, m, t_i32);
 			ir_write_str_lit(f, " 0, i32 0)");
-		} else {
+		}else {
 			// HACK NOTE(bill): This is a hack but it works because strings are created at the very end
 			// of the .ll file
 			irValue *str_array = ir_add_global_string_array(m, str);

+ 3 - 1
src/types.cpp

@@ -1088,7 +1088,9 @@ Type *core_array_type(Type *t) {
 	for (;;) {
 		Type *prev = t;
 		t = base_array_type(t);
-		if (prev == t) break;
+		if (t->kind != Type_Array && t->kind != Type_SimdVector) {
+			break;
+		}
 	}
 	return t;
 }