mirror of
git://c9x.me/qbe.git
synced 2026-04-05 18:09:47 +00:00
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
}
This commit is contained in:
parent
ae8803cbe6
commit
6838496e5c
6
fold.c
6
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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user