summary refs log tree commit diff
path: root/fold.c
diff options
context:
space:
mode:
authorAndrew Chambers <andrewchambers@fastmail.com>2019-02-27 22:10:17 +1300
committerQuentin Carbonneaux <quentin@c9x.me>2019-02-27 16:26:53 +0100
commitc043227bf792fd341cd19f40cd96b7577dacbd5a (patch)
tree140b02435306f45d188a151f647df74a29596acc /fold.c
parentb2ea8c11b61014cb90e2a025d605ac77a1c7d6bc (diff)
downloadroux-c043227bf792fd341cd19f40cd96b7577dacbd5a.tar.gz
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
Diffstat (limited to 'fold.c')
-rw-r--r--fold.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/fold.c b/fold.c
index 8fc64c5..019b739 100644
--- a/fold.c
+++ b/fold.c
@@ -500,7 +500,7 @@ opfold(int op, int cls, Con *cl, Con *cr, Fn *fn)
 
 	if ((op == Odiv || op == Oudiv
 	|| op == Orem || op == Ourem) && czero(cr, KWIDE(cls)))
-		err("null divisor in '%s'", optab[op].name);
+		return Bot;
 	if (cls == Kw || cls == Kl) {
 		if (foldint(&c, op, cls == Kl, cl, cr))
 			return Bot;