[hackers] [scc] Make constant pointers generated in decay() || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Tue, 19 Jan 2016 15:40:03 +0100 (CET)

commit abed3472b1cdf0e54d28e9e36473d7d6affaa250
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Tue Jan 19 12:11:51 2016 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Tue Jan 19 12:11:51 2016 +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.

diff --git a/cc1/expr.c b/cc1/expr.c
index ff3528e..85e42ef 100644
--- a/cc1/expr.c
+++ b/cc1/expr.c
_AT_@ -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;
         }
Received on Tue Jan 19 2016 - 15:40:03 CET

This archive was generated by hypermail 2.3.0 : Tue Jan 19 2016 - 15:48:23 CET