ref: 9f947ff3f1e8e418d43e9f201d2f293d3187a3a0
parent: f90d96846e1b756b01cb983b9e117cfb03dd755f
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Mon Nov 1 05:29:26 EDT 2021
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.
--- a/src/cmd/cc/cc1/fold.c
+++ b/src/cmd/cc/cc1/fold.c
@@ -318,7 +318,7 @@
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 @@
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)