shithub: scc

Download patch

ref: 65457f98c6d5440e3f5f888c861d18e18b6013e7
parent: f9a9c99baffaf19ec52260e79eaf1b0cd76940c4
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Jan 20 05:59:04 EST 2016

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

--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -17,7 +17,7 @@
 	Type *tp;
 	TUINT mask, nodeval;
 
-	if (!np || !np->constant)
+	if (!np || !np->constant || !np->sym)
 		return 0;
 	sym = np->sym;
 	tp = sym->type;
--- a/cc1/fold.c
+++ b/cc1/fold.c
@@ -316,8 +316,17 @@
 		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;