cproc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/cproc
Log | Files | Refs | Submodules | README | LICENSE

commit 0bb7273d42117585aeeda4610267158fcea494a6
parent ea8f0ebd571931c37aadeab0c2c57b271dee0e41
Author: Michael Forney <mforney@mforney.org>
Date:   Sat,  4 Apr 2020 19:10:47 -0700

expr: Fix type of '&' operator applied to array

It should be a pointer to the array, not to the first element (as
it would after implicit conversion without the '&' operator).

Diffstat:
Mexpr.c | 6++++++
Atest/array-address.c | 1+
Atest/array-address.qbe | 2++
3 files changed, 9 insertions(+), 0 deletions(-)

diff --git 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 @@ -0,0 +1 @@ +int x[2], y = sizeof(*&x); diff --git a/test/array-address.qbe b/test/array-address.qbe @@ -0,0 +1,2 @@ +export data $y = align 4 { w 8, } +export data $x = align 4 { z 8 }