shithub: scc

Download patch

ref: 0358d9db141b455cdf6904df1f3a4ef3f317c286
parent: b6969b7c694f8931a9077d855061543b9d47ba38
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sun Jan 22 04:42:04 EST 2017

[cc1] Remove einit in For()

Decl() is emiting the initializer and it means that in some cases
the expression is emitted in the switch and in other cases
after the switch. It is profitable to have the invariant that
the expression is emitted in the switch for all the cases.

--- a/cc1/stmt.c
+++ b/cc1/stmt.c
@@ -96,7 +96,7 @@
 For(Symbol *lbreak, Symbol *lcont, Switch *lswitch)
 {
 	Symbol *begin, *cond;
-	Node *econd, *einc, *einit = NULL;
+	Node *econd, *einc;
 
 	begin = newlabel();
 	lcont = newlabel();
@@ -115,7 +115,7 @@
 		decl();
 		break;
 	default:
-		einit = expr();
+		emit(OEXPR, expr());
 	case ';':
 		expect(';');
 		break;
@@ -125,7 +125,6 @@
 	einc = (yytoken != ')') ? expr() : NULL;
 	expect(')');
 
-	emit(OEXPR, einit);
 	emit(OJUMP, cond);
 
 	emit(OBLOOP, NULL);