commit 95ac9724aaa7e8aecbfc0b354ab30a096c08ebbd Author: Roberto E. Vargas Caballero <k...@shike2.com> AuthorDate: Wed Sep 28 11:49:57 2016 +0200 Commit: Roberto E. Vargas Caballero <k...@shike2.com> CommitDate: Wed Sep 28 11:49:57 2016 +0200
[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. diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c index 1c7b8fb..39ee9ec 100644 --- a/cc2/arch/qbe/cgen.c +++ b/cc2/arch/qbe/cgen.c @@ -428,12 +428,12 @@ swtch_if(Node *idx) 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;