[commit: packages/hoopl] master: test/Simplify: don't crash on divide by zero (4dccb47)
git at git.haskell.org
git at git.haskell.org
Mon Dec 21 22:13:38 UTC 2015
Repository : ssh://git@git.haskell.org/hoopl
On branch : master
Link : http://git.haskell.org/packages/hoopl.git/commitdiff/4dccb47429c9bb7a41cb735e572d27182061e87e
>---------------------------------------------------------------
commit 4dccb47429c9bb7a41cb735e572d27182061e87e
Author: Michal Terepeta <michal.terepeta at gmail.com>
Date: Sun Jul 5 14:43:42 2015 +0200
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.
>---------------------------------------------------------------
4dccb47429c9bb7a41cb735e572d27182061e87e
testing/Main.hs | 1 +
testing/Simplify.hs | 2 ++
testing/tests/test7 | 6 ++++++
testing/tests/test7.expected | 5 +++++
4 files changed, 14 insertions(+)
diff --git a/testing/Main.hs b/testing/Main.hs
index 000c7ac..47dbcd5 100644
--- a/testing/Main.hs
+++ b/testing/Main.hs
@@ -32,6 +32,7 @@ goldensTests = Framework.testGroup "Goldens tests"
, "test4"
, "test5"
, "test6"
+ , "test7"
, "if-test"
, "if-test2"
, "if-test3"
diff --git a/testing/Simplify.hs b/testing/Simplify.hs
index 20b4ab2..bb00dc6 100644
--- a/testing/Simplify.hs
+++ b/testing/Simplify.hs
@@ -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
diff --git a/testing/tests/test7 b/testing/tests/test7
new file mode 100644
index 0000000..9558250
--- /dev/null
+++ b/testing/tests/test7
@@ -0,0 +1,6 @@
+-- Test that we don't crash on divide by zero.
+procName() {
+L0:
+ reg1 = 42 / 0
+ ret(reg1)
+}
diff --git a/testing/tests/test7.expected b/testing/tests/test7.expected
new file mode 100644
index 0000000..e9f7ffd
--- /dev/null
+++ b/testing/tests/test7.expected
@@ -0,0 +1,5 @@
+procName() {
+L0:
+ reg1 = 42 / 0
+ ret(reg1)
+}
More information about the ghc-commits
mailing list