shithub: scc

Download patch

ref: 7d47a7ba40f28736fffc6dde3bd07a4258373cc8
parent: 65279cc59e7e5ee4c64be38923608cc552ec74d6
author: Roberto E. Vargas Caballero <[email protected]>
date: Fri Sep 4 14:38:37 EDT 2015

Simplify Switch()

It is better call directly to convert() instead of check the type
in Switch(). This patch also adds code to recover the error in
case of non integer expression.

--- a/cc1/stmt.c
+++ b/cc1/stmt.c
@@ -195,16 +195,10 @@
 
 	expect(SWITCH);
 	expect ('(');
-	cond = eval(expr());
-	/* TODO: why can I not call directly to convert here? */
 
-	switch (BTYPE(cond)) {
-	case INT:
-	case ENUM:
-		cond = convert(cond, inttype, 0);
-		break;
-	default:
-		error("incorrect type in switch statement");
+	if ((cond = convert(expr(), inttype, 0)) == NULL) {
+		errorp("incorrect type in switch statement");
+		cond = constnode(zero);
 	}
 	expect (')');