scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 8c478f26e5b418f2ac6039c25ab3ac67554f5e63
parent 81ce26fac7e8ea5221092d6bf21c8495b38e1090
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed,  1 Jan 2025 21:44:54 +0100

cc1: Accept extern addresses as constants

Only local variables have non constant addresses, and we were
only the following cases:

	- SGLOBAL: Global symbol defined in this translation unit
	- SLOCAL: Local symbol to some function
	- SPRIVATE: Private symbol defined in this translation unit

but we were forgetting extern symbols defined in some other
translation unit.

Diffstat:
Msrc/cmd/scc-cc/cc1/expr.c | 4+++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/cmd/scc-cc/cc1/expr.c b/src/cmd/scc-cc/cc1/expr.c @@ -218,7 +218,9 @@ chklvalue(Node *np) static Node * chkconstaddr(Node *var, Node *addr) { - if (var->sym && var->sym->flags & (SGLOBAL|SLOCAL|SPRIVATE) + unsigned mask = SGLOBAL|SLOCAL|SPRIVATE|SEXTERN; + + if (var->sym && var->sym->flags & mask || var->op == OFIELD && var->left->op == OSYM || var->op == OFIELD && (var->left->flags & NCONST)) { addr->flags |= NCONST;