ref: 39a70612ceb24d4fa3ffad156fa06cad9b8589ef
parent: 36cfad06bf8720ef12739b16b4664a7e6e6520d5
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Jun 17 10:31:25 EDT 2016
[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.
--- a/cc2/arch/qbe/optm.c
+++ b/cc2/arch/qbe/optm.c
@@ -11,7 +11,8 @@
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 @@
* 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;
--
⑨