shithub: scc

Download patch

ref: 92527b4272eb9d8ff6c074a3e4c3c3515cc6d2f5
parent: 2643bba93ce4239a2b1f79c82c983b42e871f389
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Sep 28 07:49:57 EDT 2016

[cc2-qbe] Jump at the end in switches

When we arrive to the end of a switch if-else-if chain
we have to jump to the default label. If we do not have
default case it means that we have to jump to the end of
the switch, but we always have to jump.

--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
@@ -428,12 +428,12 @@
 
 		switch (np->op) {
 		case OESWITCH:
-			if (deflabel) {
-				aux1.op = OJMP;
-				aux1.label = NULL;
-				aux1.u.sym = deflabel;
-				cgen(&aux1);
-			}
+			if (!deflabel)
+				deflabel = np->u.sym;
+			aux1.op = OJMP;
+			aux1.label = NULL;
+			aux1.u.sym = deflabel;
+			cgen(&aux1);
 			return;
 		case OCASE:
 			aux1 = *np;