scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 39a9a94f23d063ab01dc3a03acf7331681072e5b
parent 058e5104f68f1a0d1a0da305c7e730b2d5adb392
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue,  9 Aug 2016 14:16:20 +0200

[cc1] handle correctly arrays in address()

When a address operator is applied to an array then we do not
want to decay the array, because we want a pointer to the array
itself, not to the first element of the array. In the same way,
an array is not a lvalue, but it is legal to take a pointer to it.

Diffstat:
Mcc1/expr.c | 13+++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/cc1/expr.c b/cc1/expr.c @@ -566,16 +566,21 @@ incdec(Node *np, char op) static Node * address(char op, Node *np) { - Node *new, *left; + Node *new; /* * ansi c accepts & applied to a function name, and it generates * a function pointer */ - left = np->left; - if (np->op == OADDR && left->sym && left->type->op == FTN) - return np; + if (np->op == OSYM) { + if (np->type->op == FTN) + return decay(np); + if (np->type->op == ARY) + goto dont_check_lvalue; + } chklvalue(np); + +dont_check_lvalue: if (np->sym && (np->sym->flags & SREGISTER)) errorp("address of register variable '%s' requested", yytext); if (np->op == OPTR) {