scc

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

commit f2c91d546296c4b2c207db6c83e1f0b860649f6e
parent bcd4c47c01e02e5c9a9ae3ce749629510f7ecf5c
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 18 Jan 2023 20:30:50 +0100

cc1: Fix constness of &s.f

When the transformation of &s.f to  &s + offsetof(typeof(s), f)
is applied we have to check for the constness of the result.

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

diff --git a/src/cmd/cc/cc1/fold.c b/src/cmd/cc/cc1/fold.c @@ -372,7 +372,8 @@ static Node * foldunary(Node *np) { Node *l = np->left; - Node *aux, *aux2;; + Node *aux; + Symbol *sym; int op = l->op; switch (np->op) { @@ -400,8 +401,10 @@ foldunary(Node *np) /* &(*s).f -> s + offsetof(typeof(*s), f) */ if (op == OFIELD && l->left->op == OPTR) { DBG("FOLD collapse '&(*s).f' %d", np->op); - aux = offsetnode(l->right->sym, np->type); - aux = node(OADD, np->type, l->left->left, aux); + aux = node(OADD, + np->type, + l->left->left, + offsetnode(l->right->sym, np->type)); if (aux->left->flags & NCONST) aux->flags |= NCONST; @@ -413,11 +416,12 @@ foldunary(Node *np) /* &s.f -> &s + offsetof(typeof(s), f) */ if (op == OFIELD) { DBG("FOLD collapse '&s.f' %d", np->op); - aux = offsetnode(l->right->sym, np->type); - aux2 = node(OADDR, np->type, l->left, NULL); - aux = node(OADD, np->type, aux2, aux); + aux = node(OADD, + np->type, + node(OADDR, np->type, l->left, NULL), + offsetnode(l->right->sym, np->type)); - if (l->flags & NCONST) + if (np->flags & NCONST) aux->flags |= NCONST; l->left = NULL; freetree(np);