scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 04e4de26ba4989ab84136e52169fc7bead5e8cf3
parent e2548f029977708f67328a66a45dec089996d831
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri,  5 Nov 2021 04:15:41 +0100

cc1: Simplify Return()

Diffstat:
Msrc/cmd/cc/cc1/stmt.c | 15++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/cmd/cc/cc1/stmt.c b/src/cmd/cc/cc1/stmt.c @@ -170,22 +170,23 @@ Dowhile(Symbol *lbreak, Symbol *lcont, Switch *lswitch) static void Return(Symbol *lbreak, Symbol *lcont, Switch *lswitch) { - Node *np; + Node *np = NULL; Type *tp = curfun->type->type; expect(RETURN); - np = (yytoken != ';') ? decay(expr()) : NULL; + if (yytoken != ';') + np = decay(expr()); expect(';'); - if (!np) { - if (tp != voidtype) - warn("function returning non void returns no value"); - tp = voidtype; - } else if (np->type != tp) { + + if (!np && tp != voidtype) + warn("function returning non void returns no value"); + else if (np && np->type != tp) { if (tp == voidtype) warn("function returning void returns a value"); else if ((np = convert(np, tp, 0)) == NULL) errorp("incorrect type in return"); } + emit(ORET, NULL); emit(OEXPR, np); }