scc

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

commit abed3472b1cdf0e54d28e9e36473d7d6affaa250
parent ee4660c4b1081fbe4d5ae68a68132f9e1b629a5c
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 19 Jan 2016 12:11:51 +0100

Make constant pointers generated in decay()

When a pointer generated in decay() comes from a lvalue with
static storage then it is a constant value.

Diffstat:
Mcc1/expr.c | 8++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/cc1/expr.c b/cc1/expr.c @@ -199,19 +199,23 @@ chklvalue(Node *np) Node * decay(Node *np) { + Node *new; Type *tp = np->type; switch (tp->op) { case ARY: tp = tp->type; if (np->op == OPTR) { - Node *new = np->left; + new = np->left; free(np); new->type = mktype(tp, PTR, 0, NULL); return new; } case FTN: - np = node(OADDR, mktype(tp, PTR, 0, NULL), np, NULL); + new = node(OADDR, mktype(tp, PTR, 0, NULL), np, NULL); + if (np->sym && np->sym->flags & (ISGLOBAL|ISLOCAL|ISPRIVATE)) + new->constant = 1; + return new; default: return np; }