From 6fabc79d81de56b6c1cdcc2242933fd792e2ddf9 Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Fri, 5 Aug 2022 12:43:48 -0700 Subject: 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. --- expr.c | 2 +- test/initializer-member-static.c | 2 ++ test/initializer-member-static.qbe | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 test/initializer-member-static.c create mode 100644 test/initializer-member-static.qbe diff --git a/expr.c b/expr.c index 9868c4c..6eb1b3a 100644 --- a/expr.c +++ b/expr.c @@ -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) { diff --git a/test/initializer-member-static.c b/test/initializer-member-static.c new file mode 100644 index 0000000..7433a33 --- /dev/null +++ b/test/initializer-member-static.c @@ -0,0 +1,2 @@ +extern struct { int x; } s; +int *p = &s.x; diff --git a/test/initializer-member-static.qbe b/test/initializer-member-static.qbe new file mode 100644 index 0000000..c603c64 --- /dev/null +++ b/test/initializer-member-static.qbe @@ -0,0 +1 @@ +export data $p = align 8 { l $s + 0, } -- cgit v1.2.3