commit 3182c9c3bcfd64f88e0dbd3cd8a6cef26a49b237
Author:     Roberto E. Vargas Caballero <[email protected]>
AuthorDate: Fri Jun 17 14:31:25 2016 +0200
Commit:     Roberto E. Vargas Caballero <[email protected]>
CommitDate: Fri Jun 17 14:31:25 2016 +0200

    [cc2-qbe] Fix additional return code
    
    This additional return is added because we need
    a jump instruction to the end of basic blocks,
    but the last addition of OEFUN broke the previous
    logic.

diff --git a/cc2/arch/qbe/optm.c b/cc2/arch/qbe/optm.c
index a614b75..929d976 100644
--- a/cc2/arch/qbe/optm.c
+++ b/cc2/arch/qbe/optm.c
@@ -11,7 +11,8 @@ optm_dep(Node *np)
        Node *p, *dst, *next = np->next;
        Symbol *sym, *osym;
 
-       if (!next) {
+       switch (op) {
+       case OEFUN:
                /*
                 * In QBE we need at the end of a basic block
                 * a jump, so we have to ensure that the last
@@ -22,12 +23,10 @@ optm_dep(Node *np)
                 * a ret there, and in the case of branches
                 * we need a label for the next statement
                 */
-               if (op == ONOP || op == OBRANCH || (op != ORET && op != OJMP))
+               op = (np->prev) ? np->prev->op : 0;
+               if (!op || op == ONOP || op == OBRANCH || (op != ORET && op != 
OJMP))
                        addstmt(newnode(ORET), KEEPCUR);
-               next = np->next;
-       }
-
-       switch (op) {
+               break;
        case ONOP:
                if (next->op == ONOP) {
                        sym = np->u.sym;

Reply via email to