ref: ed1a8159a3f06e7c4da43567e8dee276d392f3bd
parent: 42fd80186eb88ab683c82a866366d2c72657e1ac
author: Roberto E. Vargas Caballero <[email protected]>
date: Mon Nov 1 12:03:26 EDT 2021
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.
--- a/src/cmd/cc/cc1/fold.c
+++ b/src/cmd/cc/cc1/fold.c
@@ -293,6 +293,7 @@
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 @@
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 @@
default:
return np;
}
+
DBG("FOLD cast %c->%c", oldtp->letter, newtp->letter);
freetree(np);
sym = newsym(NS_IDEN, NULL);