~mcf/cproc

6fabc79d81de56b6c1cdcc2242933fd792e2ddf9 — Michael Forney a month ago dc7e08c master
expr: Fix constant evaluation of struct member address

fb00ba6978 had the side-effect of introducing an integer to pointer
cast, which was not evaluated as a constant expression. To fix this,
just set the type of the expression.
3 files changed, 4 insertions(+), 1 deletions(-)

M expr.c
A test/initializer-member-static.c
A test/initializer-member-static.qbe
M expr.c => expr.c +1 -1
@@ 958,7 958,7 @@ postfixexpr(struct scope *s, struct expr *r)
			if (!m)
				error(&tok.loc, "struct/union has no member named '%s'", tok.lit);
			r = mkbinaryexpr(&tok.loc, TADD, exprconvert(r, &typeulong), mkconstexpr(&typeulong, offset));
			r = exprconvert(r, mkpointertype(m->type, tq | m->qual));
			r->type = mkpointertype(m->type, tq | m->qual);
			r = mkunaryexpr(TMUL, r);
			r->lvalue = lvalue;
			if (m->bits.before || m->bits.after) {

A test/initializer-member-static.c => test/initializer-member-static.c +2 -0
@@ 0,0 1,2 @@
extern struct { int x; } s;
int *p = &s.x;

A test/initializer-member-static.qbe => test/initializer-member-static.qbe +1 -0
@@ 0,0 1,1 @@
export data $p = align 8 { l $s + 0, }