scc

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

commit 9f947ff3f1e8e418d43e9f201d2f293d3187a3a0
parent f90d96846e1b756b01cb983b9e117cfb03dd755f
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon,  1 Nov 2021 09:29:26 +0100

cc1: Remove wrong cast simpleifications

Casts cannot be collapse, because every cast can modify
the value (truncating values). The correct behaviour
is to call foldcast() and let it to do at compilation
time the work that should be done at execution time.

Diffstat:
Msrc/cmd/cc/cc1/fold.c | 11++---------
1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/src/cmd/cc/cc1/fold.c b/src/cmd/cc/cc1/fold.c @@ -318,7 +318,7 @@ foldcast(Node *np, Node *l) Type *newtp = np->type, *oldtp = l->type; Symbol aux, *sym, *osym = l->sym; - if (!(l->flags & NCONST)) + if ((l->flags & NCONST) == 0) return np; switch (newtp->op) { @@ -381,14 +381,7 @@ foldunary(Node *np, Node *l) freetree(np); return l; case OCAST: - if (op != OCAST) - return foldcast(np, l); - /* TODO: This is wrong: (float)(int) 7.2 */ - DBG("FOLD unary collapse %d", np->op); - np->left = l->left; - l->left = NULL; - freetree(l); - return np; + return foldcast(np, l); case OSNEG: case OCPL: if (op != np->op)