[hackers] [scc] Do not fold expressions with static addresses || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Wed, 20 Jan 2016 16:02:22 +0100 (CET)

commit 65457f98c6d5440e3f5f888c861d18e18b6013e7
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Wed Jan 20 10:59:04 2016 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Wed Jan 20 10:59:04 2016 +0100

    Do not fold expressions with static addresses
    
    Static addresses are constant values, but he don't know
    the value of them in the frontend, so they cannot be folded

diff --git a/cc1/expr.c b/cc1/expr.c
index bc8981f..1db5746 100644
--- a/cc1/expr.c
+++ b/cc1/expr.c
_AT_@ -17,7 +17,7 @@ cmpnode(Node *np, TUINT val)
         Type *tp;
         TUINT mask, nodeval;
 
- if (!np || !np->constant)
+ if (!np || !np->constant || !np->sym)
                 return 0;
         sym = np->sym;
         tp = sym->type;
diff --git a/cc1/fold.c b/cc1/fold.c
index 7bddbdf..7448656 100644
--- a/cc1/fold.c
+++ b/cc1/fold.c
_AT_@ -316,8 +316,17 @@ fold(int op, Type *tp, Node *lp, Node *rp)
                 warn("division by 0");
                 return NULL;
         }
- if (!lp->constant || rp && !rp->constant)
+ /*
+ * Return if any of the children is no constant,
+ * or it is a constant generated when
+ * the address of a static variable is taken
+ * (when we don't know the physical address so
+ * we cannot fold it)
+ */
+ if (!lp->constant || !lp->sym ||
+ rp && (!rp->constant || !rp->sym)) {
                 return NULL;
+ }
         optype = lp->type;
         ls = lp->sym;
         rs = (rp) ? rp->sym : NULL;
Received on Wed Jan 20 2016 - 16:02:22 CET

This archive was generated by hypermail 2.3.0 : Wed Jan 20 2016 - 16:12:18 CET