aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--expr.c6
-rw-r--r--test/array-address.c1
-rw-r--r--test/array-address.qbe2
3 files changed, 9 insertions, 0 deletions
diff --git a/expr.c b/expr.c
index 4762d7a..2508879 100644
--- a/expr.c
+++ b/expr.c
@@ -119,6 +119,12 @@ mkunaryexpr(enum tokenkind op, struct expr *base)
switch (op) {
case TBAND:
if (base->decayed) {
+ /*
+ An array gets decayed to a pointer to its first element,
+ but with an explicit '&' operator, it is a pointer to
+ the array.
+ */
+ base->type = mkpointertype(base->base->type, base->base->qual);
base->decayed = false;
return base;
}
diff --git a/test/array-address.c b/test/array-address.c
new file mode 100644
index 0000000..22ebe4b
--- /dev/null
+++ b/test/array-address.c
@@ -0,0 +1 @@
+int x[2], y = sizeof(*&x);
diff --git a/test/array-address.qbe b/test/array-address.qbe
new file mode 100644
index 0000000..d32d555
--- /dev/null
+++ b/test/array-address.qbe
@@ -0,0 +1,2 @@
+export data $y = align 4 { w 8, }
+export data $x = align 4 { z 8 }