Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "zero divided by n" (part of this was MPR#7201) #954

Merged
merged 1 commit into from Dec 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions Changes
Expand Up @@ -11,6 +11,10 @@ Next version (4.05.0):
(Stephen Dolan, review by Alain Frisch, Pierre Chambart, Mark
Shinwell, Gabriel Scherer and Damien Doligez)

- MPR#7201, GPR#954: Correct wrong optimisation of "0 / <expr>"
and "0 mod <expr>" in the case when <expr> was a non-constant
evaluating to zero (Mark Shinwell)

### Runtime system:

### Type system:
Expand Down
4 changes: 0 additions & 4 deletions asmcomp/cmmgen.ml
Expand Up @@ -339,8 +339,6 @@ let rec div_int c1 c2 is_safe dbg =
Csequence(c1, raise_symbol dbg "caml_exn_Division_by_zero")
| (c1, Cconst_int 1) ->
c1
| (Cconst_int 0 as c1, c2) ->
Csequence(c2, c1)
| (Cconst_int n1, Cconst_int n2) ->
Cconst_int (n1 / n2)
| (c1, Cconst_int n) when n <> min_int ->
Expand Down Expand Up @@ -387,8 +385,6 @@ let mod_int c1 c2 is_safe dbg =
Csequence(c1, raise_symbol dbg "caml_exn_Division_by_zero")
| (c1, Cconst_int (1 | (-1))) ->
Csequence(c1, Cconst_int 0)
| (Cconst_int 0, c2) ->
Csequence(c2, Cconst_int 0)
| (Cconst_int n1, Cconst_int n2) ->
Cconst_int (n1 mod n2)
| (c1, (Cconst_int n as c2)) when n <> min_int ->
Expand Down
17 changes: 17 additions & 0 deletions testsuite/tests/basic/zero_divided_by_n.ml
@@ -0,0 +1,17 @@
(* Mantis 7201 *)

let f () = 0 [@@inline never]

let () =
try
ignore ((0 / f ()) : int);
assert false
with Division_by_zero -> ()

(* Not in Mantis 7201, but related: *)

let () =
try
ignore ((0 mod f ()) : int);
assert false
with Division_by_zero -> ()