commit b163099eeca09217177482d7502bf8d6703dad76
parent 2f1edab1b0ee2af6635bf41644eda6a25c4471c3
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Mon, 18 Jan 2016 17:39:03 +0100
Mark as constant nodes address of static variables
This operation generates a constant node which can be used
in initializers.
Diffstat:
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/cc1/expr.c b/cc1/expr.c
@@ -544,6 +544,8 @@ incdec(Node *np, char op)
static Node *
address(char op, Node *np)
{
+ Node *new;
+
if (BTYPE(np) != FTN) {
chklvalue(np);
if (np->symbol && (np->sym->flags & ISREGISTER))
@@ -554,7 +556,11 @@ address(char op, Node *np)
return new;
}
}
- return node(op, mktype(np->type, PTR, 0, NULL), np, NULL);
+ new = node(op, mktype(np->type, PTR, 0, NULL), np, NULL);
+
+ if (np->symbol && np->sym->flags & (ISGLOBAL|ISLOCAL|ISPRIVATE))
+ new->constant = 1;
+ return new;
}
static Node *