scc

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

commit aca5772fe06bafc1a91c6360fce527f0c5bc8a92
parent 19ae8097e83162421de52d73efd05bc717de0618
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed,  4 Jan 2023 19:20:05 +0100

cc1: Remove simplify() call in expr()

Expr() is called in different contexts and simplify() is called
several times for the same tree making hard to follow where the
simplifications are done and how they are done.

Diffstat:
Msrc/cmd/cc/cc1/expr.c | 2+-
Msrc/cmd/cc/cc1/stmt.c | 9+++++----
2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/cmd/cc/cc1/expr.c b/src/cmd/cc/cc1/expr.c @@ -1113,7 +1113,7 @@ expr(void) lp = node(OCOMMA, rp->type, lp, rp); } - return simplify(lp); + return lp; } Node * diff --git a/src/cmd/cc/cc1/stmt.c b/src/cmd/cc/cc1/stmt.c @@ -47,7 +47,7 @@ stmtexp(Symbol *lbreak, Symbol *lcont, Switch *lswitch) stmt(lbreak, lcont, lswitch); return; } - np = expr(); + np = simplify(expr()); if ((np->flags & NEFFECT) == 0) warn("expression without side effects"); emit(OEXPR, np); @@ -115,14 +115,14 @@ For(Symbol *lbreak, Symbol *lcont, Switch *lswitch) decl(); break; default: - emit(OEXPR, expr()); + emit(OEXPR, simplify(expr())); case ';': expect(';'); break; } econd = (yytoken != ';') ? condexpr(NONEGATE) : NULL; expect(';'); - einc = (yytoken != ')') ? expr() : NULL; + einc = (yytoken != ')') ? simplify(expr()) : NULL; expect(')'); emit(OJUMP, cond); @@ -248,7 +248,8 @@ Swtch(Symbol *obr, Symbol *lcont, Switch *osw) expect(SWITCH); expect ('('); - if ((cond = convert(expr(), inttype, 0)) == NULL) { + cond = simplify(convert(expr(), inttype, 0)); + if (cond == NULL) { errorp("incorrect type in switch statement"); cond = constnode(zero); }