commit b163099eeca09217177482d7502bf8d6703dad76
Author:     Roberto E. Vargas Caballero <[email protected]>
AuthorDate: Mon Jan 18 17:39:03 2016 +0100
Commit:     Roberto E. Vargas Caballero <[email protected]>
CommitDate: Mon Jan 18 17:39:03 2016 +0100

    Mark as constant nodes address of static variables
    
    This operation generates a constant node which can be used
    in initializers.

diff --git a/cc1/expr.c b/cc1/expr.c
index 5494505..ff3528e 100644
--- 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 *

Reply via email to