shithub: scc

Download patch

ref: a0796b4c04fdb332658a59a571897a4db17a3bbe
parent: f971c72c570d9836184ee6beca0757fd87498b37
author: Roberto E. Vargas Caballero <[email protected]>
date: Thu Oct 9 14:03:21 EDT 2014

Fix cast()
This function has a problem because a '(' can means a expression
between parentheses or may be a cast. If we read the '(' then
we cannot call to unary(), because then primary() will not read
the parenthesis needed for calling expr(). The solution of course
is to call expr() directly in cast().

This function is called when

--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -559,15 +559,17 @@
 }
 
 static Node *
-cast2(void)
+cast(void)
 {
 	register Node *np1, *np2;
 	register Type *tp;
 
-	switch(yytoken) {
+	if (!accept('('))
+		return unary();
+
+	switch (yytoken) {
 	case TQUALIFIER: case TYPE:
 		tp = typename();
-		expect(')');
 		switch (tp->op) {
 		case ARY:
 			error("cast specify an array type");
@@ -582,17 +584,12 @@
 		}
 		break;
 	default:
-		np2 = unary();
-		expect(')');
+		np2 = expr();
 		break;
 	}
-	return np2;
-}
+	expect(')');
 
-static Node *
-cast(void)
-{
-	return (accept('(')) ? cast2() : unary();
+	return np2;
 }
 
 static Node *