A valid non-void function should not return VOID. VOID can only be returned if no return statements have been issued. Note: even if the expression is erroneous, and thus VOID, this returned value would be via a phi-node. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> --- ir.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ir.c b/ir.c index 836d4eb24..2e284c251 100644 --- a/ir.c +++ b/ir.c @@ -107,6 +107,17 @@ static int check_switch(struct entrypoint *ep, struct instruction *insn) return err; } +static int check_return(struct instruction *insn) +{ + struct symbol *ctype = insn->type; + + if (ctype && ctype->bit_size > 0 && insn->src == VOID) { + sparse_error(insn->pos, "return without value"); + return 1; + } + return 0; +} + static int validate_insn(struct entrypoint *ep, struct instruction *insn) { int err = 0; @@ -152,6 +163,10 @@ static int validate_insn(struct entrypoint *ep, struct instruction *insn) err += check_user(insn, insn->src); break; + case OP_RET: + err += check_return(insn); + break; + case OP_BR: err += check_branch(ep, insn, insn->bb_true); break; -- 2.18.0