scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 65457f98c6d5440e3f5f888c861d18e18b6013e7
parent f9a9c99baffaf19ec52260e79eaf1b0cd76940c4
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 20 Jan 2016 10:59:04 +0100

Do not fold expressions with static addresses

Static addresses are constant values, but he don't know
the value of them in the frontend, so they cannot be folded

Diffstat:
Mcc1/expr.c | 2+-
Mcc1/fold.c | 11++++++++++-
2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/cc1/expr.c b/cc1/expr.c @@ -17,7 +17,7 @@ cmpnode(Node *np, TUINT val) Type *tp; TUINT mask, nodeval; - if (!np || !np->constant) + if (!np || !np->constant || !np->sym) return 0; sym = np->sym; tp = sym->type; diff --git a/cc1/fold.c b/cc1/fold.c @@ -316,8 +316,17 @@ fold(int op, Type *tp, Node *lp, Node *rp) warn("division by 0"); return NULL; } - if (!lp->constant || rp && !rp->constant) + /* + * Return if any of the children is no constant, + * or it is a constant generated when + * the address of a static variable is taken + * (when we don't know the physical address so + * we cannot fold it) + */ + if (!lp->constant || !lp->sym || + rp && (!rp->constant || !rp->sym)) { return NULL; + } optype = lp->type; ls = lp->sym; rs = (rp) ? rp->sym : NULL;