commit 6838496e5c990339755577eb16b949fe2f47790e
parent ae8803cbe655f64a2ef1739c8dfc5c12af99bdfb
Author: Michael Forney <mforney@mforney.org>
Date: Tue, 2 Jul 2019 20:32:09 -0700
fold: Don't fold invalid addition/subtraction rather than failing
This may happen in a branch QBE doesn't realize is unreachable,
for example (simplified from real code found in ncurses)
data $str = { b "abcdef", b 0 }
function l $f(w %x) {
@start
%.1 =w ceqw %x, 0
jnz %.1, @logic_join, @logic_right
@logic_right
%p =l call $strchr(l $str, w %x)
%.2 =w ceql %p, 0
@logic_join
%.3 =w phi @start %.1, @logic_right %.2
jnz %.3, @fail, @return
@fail
ret 0
@return
%.4 =l sub %p, $str
ret %.4
}
Diffstat:
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/fold.c b/fold.c
@@ -343,7 +343,7 @@ foldint(Con *res, int op, int w, Con *cl, Con *cr)
if (op == Oadd) {
if (cl->type == CAddr) {
if (cr->type == CAddr)
- err("undefined addition (addr + addr)");
+ return 1;
lab = cl->label;
typ = CAddr;
}
@@ -358,10 +358,10 @@ foldint(Con *res, int op, int w, Con *cl, Con *cr)
lab = cl->label;
typ = CAddr;
} else if (cl->label != cr->label)
- err("undefined substraction (addr1 - addr2)");
+ return 1;
}
else if (cr->type == CAddr)
- err("undefined substraction (num - addr)");
+ return 1;
}
else if (cl->type == CAddr || cr->type == CAddr) {
if (Ocmpl <= op && op <= Ocmpl1)