Adding some more internal-error messages where they were missing; fixed ast_ternary_codegen to use the ast_node's type instead of the ir generated ones to avoid erroring on TYPE_NIL

This commit is contained in:
Wolfgang Bumiller 2012-12-31 12:08:47 +01:00
parent a170154927
commit 26d43e650f
2 changed files with 9 additions and 4 deletions

9
ast.c
View file

@ -2399,15 +2399,18 @@ bool ast_ternary_codegen(ast_ternary *self, ast_function *func, bool lvalue, ir_
/* Here, now, we need a PHI node /* Here, now, we need a PHI node
* but first some sanity checking... * but first some sanity checking...
*/ */
if (trueval->vtype != falseval->vtype) { if (trueval->vtype != falseval->vtype && trueval->vtype != TYPE_NIL && falseval->vtype != TYPE_NIL) {
/* error("ternary with different types on the two sides"); */ /* error("ternary with different types on the two sides"); */
compile_error(ast_ctx(self), "internal error: ternary operand types invalid");
return false; return false;
} }
/* create PHI */ /* create PHI */
phi = ir_block_create_phi(merge, ast_ctx(self), ast_function_label(func, "phi"), trueval->vtype); phi = ir_block_create_phi(merge, ast_ctx(self), ast_function_label(func, "phi"), self->expression.vtype);
if (!phi) if (!phi) {
compile_error(ast_ctx(self), "internal error: failed to generate phi node");
return false; return false;
}
ir_phi_add(phi, ontrue_out, trueval); ir_phi_add(phi, ontrue_out, trueval);
ir_phi_add(phi, onfalse_out, falseval); ir_phi_add(phi, onfalse_out, falseval);

4
ir.c
View file

@ -772,8 +772,10 @@ bool ir_function_finalize(ir_function *self)
} }
} }
if (!ir_function_naive_phi(self)) if (!ir_function_naive_phi(self)) {
irerror(self->context, "internal error: ir_function_naive_phi failed");
return false; return false;
}
for (i = 0; i < vec_size(self->locals); ++i) { for (i = 0; i < vec_size(self->locals); ++i) {
ir_value *v = self->locals[i]; ir_value *v = self->locals[i];