ref: abed3472b1cdf0e54d28e9e36473d7d6affaa250
parent: ee4660c4b1081fbe4d5ae68a68132f9e1b629a5c
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Jan 19 07:11:51 EST 2016
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.
--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -199,6 +199,7 @@
Node *
decay(Node *np)
{
+ Node *new;
Type *tp = np->type;
switch (tp->op) {
@@ -205,13 +206,16 @@
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;
}