Commit 4dccb474 authored by Michal Terepeta's avatar Michal Terepeta

test/Simplify: don't crash on divide by zero

Currently test/Simplify would not check for 0 before trying to do
constant folding, which is quite bad since it simply crashes the
program.

The fix is to simply avoid evaluating the expression if there is a
division by zero.
parent 782ffec3
......@@ -32,6 +32,7 @@ goldensTests = Framework.testGroup "Goldens tests"
, "test4"
, "test5"
, "test6"
, "test7"
, "if-test"
, "if-test2"
, "if-test3"
......
......@@ -27,6 +27,8 @@ simplify = deepFwdRw simp
= Just $ Lit $ Int $ n1 + n2
-- ... more cases for constant folding
-- @ end cprop.tex
s_exp (Binop Div _lhs (Lit (Int 0)))
= Nothing
s_exp (Binop opr e1 e2)
| (Just op, Lit (Int i1), Lit (Int i2)) <- (intOp opr, e1, e2) =
Just $ Lit $ Int $ op i1 i2
......
-- Test that we don't crash on divide by zero.
procName() {
L0:
reg1 = 42 / 0
ret(reg1)
}
procName() {
L0:
reg1 = 42 / 0
ret(reg1)
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment