mirror of
git://c9x.me/qbe.git
synced 2026-04-05 18:09:47 +00:00
Let runtime crash on zero div, don't fold it.
Remarks from Quentin:
It is an important decision to use Bot
and not Top as the result of 'x / 0'.
By using Bot, we refuse to give a warrant
to the compiler that would allow meaningless
subsequent decisions. An example follows.
Clang, on my computer, will build a program
which prints "Ho" when fed the following C:
int main()
{ puts(1/0 ? "Hi" : "Ho"); }
On the other hand, a C compiler based on
QBE will build a program which crashes,
as one would expect.
See also
https://c9x.me/notes/2014-09-10.html
This commit is contained in:
parent
b2ea8c11b6
commit
c043227bf7
2
fold.c
2
fold.c
@ -500,7 +500,7 @@ opfold(int op, int cls, Con *cl, Con *cr, Fn *fn)
|
|||||||
|
|
||||||
if ((op == Odiv || op == Oudiv
|
if ((op == Odiv || op == Oudiv
|
||||||
|| op == Orem || op == Ourem) && czero(cr, KWIDE(cls)))
|
|| op == Orem || op == Ourem) && czero(cr, KWIDE(cls)))
|
||||||
err("null divisor in '%s'", optab[op].name);
|
return Bot;
|
||||||
if (cls == Kw || cls == Kl) {
|
if (cls == Kw || cls == Kl) {
|
||||||
if (foldint(&c, op, cls == Kl, cl, cr))
|
if (foldint(&c, op, cls == Kl, cl, cr))
|
||||||
return Bot;
|
return Bot;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user