aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2022-08-05 12:43:48 -0700
committerMichael Forney <mforney@mforney.org>2022-08-05 12:43:48 -0700
commit6fabc79d81de56b6c1cdcc2242933fd792e2ddf9 (patch)
tree4e7b357ff9f1703ae452034fa7161b9da432f4c7
parentdc7e08ca0aaa21b9f62944e237f3fa068b40106f (diff)
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.
-rw-r--r--expr.c2
-rw-r--r--test/initializer-member-static.c2
-rw-r--r--test/initializer-member-static.qbe1
3 files changed, 4 insertions, 1 deletions
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, }