scc

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

commit a1b342cd3ccc71c40abffb48cc1c5003081074ee
parent 1435040bbb43b79aae3e2a254a49229501981116
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)