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

This commit is contained in:
gingerBill
2019-11-20 22:07:12 +00:00
parent 69afa33fa5
commit e01d8a04a9
2 changed files with 19 additions and 3 deletions

View File

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

View File

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