[hackers] [scc] [cc1] handle correctly arrays in address() || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Tue, 9 Aug 2016 14:25:44 +0200 (CEST)

commit 39a9a94f23d063ab01dc3a03acf7331681072e5b
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Tue Aug 9 14:16:20 2016 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
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
_AT_@ -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) {
Received on Tue Aug 09 2016 - 14:25:44 CEST

This archive was generated by hypermail 2.3.0 : Tue Aug 09 2016 - 14:36:29 CEST