shithub: scc

Download patch

ref: 045728bdd4ff3888733cbf0ae65a93b15d39c2ec
parent: 72415218413b75d436592eab0963a84a27e7974d
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Aug 9 10:16:20 EDT 2016

[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.

--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -566,16 +566,21 @@
 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) {