shithub: scc

Download patch

ref: b163099eeca09217177482d7502bf8d6703dad76
parent: 2f1edab1b0ee2af6635bf41644eda6a25c4471c3
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Mon Jan 18 12:39:03 EST 2016

Mark as constant nodes address of static variables

This operation generates a constant node which can be used
in initializers.

--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -544,6 +544,8 @@
 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 @@
 			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 *