shithub: scc

Download patch

ref: b4d92e02bc635472f47ca877add11b4581392238
parent: 65d6ca357dd5101c7ef095b30ad021ba1339c96f
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Apr 15 09:12:42 EDT 2014

Check if variable is register type before taken address

It is forbidden to take the address of a variable defined as
register.

--- a/expr.c
+++ b/expr.c
@@ -369,7 +369,7 @@
 {
 	register Node *np;
 	Type *tp;
-	char paren, op;
+	char paren, op, *err;
 	uint8_t t;
 
 	switch (yytoken) {
@@ -410,8 +410,9 @@
 	switch (op) {
 	case OADDR:
 		if (!np->b.lvalue)
-			goto bad_operand;
-		/* TODO: check if variable is register */
+			goto no_lvalue;
+		if (np->code == emitsym && np->u.sym->s.isregister)
+			goto reg_address;
 		tp = mktype(tp, PTR, NULL, 0);
 		break;
 	case OEXC:
@@ -438,8 +439,16 @@
 
 	return unarycode(op, tp, np);
 
+no_lvalue:
+	err = "lvalue required in unary expression";
+	goto error;
+reg_address:
+	err = "address of register variable '%s' requested";
+	goto error;
 bad_operand:
-	error("bad operand in unary expression");
+	err = "bad operand in unary expression";
+error:
+	error(err, yytext);
 }
 
 static Node *