commit 39a9a94f23d063ab01dc3a03acf7331681072e5b
Author:     Roberto E. Vargas Caballero <[email protected]>
AuthorDate: Tue Aug 9 14:16:20 2016 +0200
Commit:     Roberto E. Vargas Caballero <[email protected]>
CommitDate: Tue Aug 9 14:16:20 2016 +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.

diff --git a/cc1/expr.c b/cc1/expr.c
index 138ad48..c7f7e1a 100644
--- 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) {

Reply via email to