scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 95ac9724aaa7e8aecbfc0b354ab30a096c08ebbd
parent 44123dfb36d1c0ba6b428d89a870679f4f7ff86e
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 28 Sep 2016 11:49:57 +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.

Diffstat:
Mcc2/arch/qbe/cgen.c | 12++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git 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;