commit ed1a8159a3f06e7c4da43567e8dee276d392f3bd
parent 42fd80186eb88ab683c82a866366d2c72657e1ac
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Mon, 1 Nov 2021 16:03:26 +0100
cc1: Fold pointer constants
The case of a pointer constant was missed in foldconst()
that implied a dangerous default case that generated a
dangling node without a specified value. To avoid having
this case in the future we add a default case with an
abort.
Diffstat:
1 file changed, 4 insertions(+), 0 deletions(-)
diff --git a/src/cmd/cc/cc1/fold.c b/src/cmd/cc/cc1/fold.c
@@ -293,6 +293,7 @@ foldconst(int type, int op, Type *tp, Symbol *ls, Symbol *rs)
if (!foldint(op, &aux, ls->u.i, i))
return NULL;
break;
+ case PTR:
case UNSIGNED:
u = (rs) ? rs->u.u : 0u;
if (!folduint(op, &aux, ls->u.u, u))
@@ -303,6 +304,8 @@ foldconst(int type, int op, Type *tp, Symbol *ls, Symbol *rs)
if (!foldfloat(op, &aux, ls->u.f, f))
return NULL;
break;
+ default:
+ abort();
}
sym = newsym(NS_IDEN, NULL);
sym->flags |= SCONSTANT;
@@ -355,6 +358,7 @@ foldcast(Node *np, Node *l)
default:
return np;
}
+
DBG("FOLD cast %c->%c", oldtp->letter, newtp->letter);
freetree(np);
sym = newsym(NS_IDEN, NULL);