shithub: scc

Download patch

ref: cb8b536d8b84402c372f610efed3e1a6e852f65d
parent: ad2d3ea7a4b95be09db3643e96b9e485e3296e81
author: Roberto E. Vargas Caballero <[email protected]>
date: Wed Jul 29 06:01:29 EDT 2015

Add compile time calculation of constant ?:

--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -1065,6 +1065,18 @@
 		expect(':');
 		ifno = promote(ternary());
 		typeconv(&ifyes, &ifno);
+		if (cond->constant) {
+			TINT i = cond->sym->u.i;
+
+			freetree(cond);
+			if (i == 0) {
+				freetree(ifyes);
+				return ifno;
+			} else {
+				freetree(ifno);
+				return ifyes;
+			}
+		}
 		np = node(OCOLON, ifyes->type, ifyes, ifno);
 		cond = node(OASK, np->type, cond, np);
 	}