ast_function_codegen: Add a return instruction if it is missing, or error if we're not in a void-function

This commit is contained in:
Wolfgang (Blub) Bumiller 2012-05-03 14:15:02 +02:00
parent bd84ebcf74
commit 46122235e6

13
ast.c
View file

@ -545,6 +545,19 @@ bool ast_function_codegen(ast_function *self, ir_builder *ir)
if (!(*gen)((ast_expression*)self->blocks[i], self, false, &dummy))
return false;
}
/* TODO: check return types */
if (!self->curblock->is_return)
{
if (!self->vtype->expression.next ||
self->vtype->expression.next->expression.vtype == TYPE_VOID)
return ir_block_create_return(self->curblock, NULL);
else
{
/* error("missing return"); */
return false;
}
}
return true;
}