From: Christoph Mallon Date: Tue, 13 Nov 2007 21:06:52 +0000 (+0000) Subject: Handle non-void functions which miss a return statement at the end. Especially handl... X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=bfe76ff46dbc10738f330e87edc21f6b55875a20;p=cparser Handle non-void functions which miss a return statement at the end. Especially handle the special case of main() returning 0. [r18384] --- diff --git a/ast2firm.c b/ast2firm.c index 62793e5..ebe3957 100644 --- a/ast2firm.c +++ b/ast2firm.c @@ -1532,7 +1532,22 @@ static void create_function(declaration_t *declaration) /* do we have a return statement yet? */ if(get_cur_block() != NULL) { - ir_node *ret = new_Return(get_store(), 0, NULL); + assert(declaration->type->type == TYPE_FUNCTION); + const function_type_t* const func_type = (const function_type_t*)declaration->type; + ir_node *ret; + if (func_type->result_type == type_void) { + ret = new_Return(get_store(), 0, NULL); + } else { + ir_mode *const mode = get_ir_mode(func_type->result_type); + ir_node * in[1]; + // §5.1.2.2.3 main implicitly returns 0 + if (strcmp(declaration->symbol->string, "main") == 0) { + in[0] = new_Const(mode, get_mode_null(mode)); + } else { + in[0] = new_Unknown(mode); + } + ret = new_Return(get_store(), 1, in); + } add_immBlock_pred(end_block, ret); }