summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--asmcomp/cmmgen.ml14
-rw-r--r--testsuite/tests/basic/pr7533.ml19
-rw-r--r--testsuite/tests/basic/pr7533.reference0
3 files changed, 27 insertions, 6 deletions
diff --git a/asmcomp/cmmgen.ml b/asmcomp/cmmgen.ml
index fd21651f0c..9ed83c9c77 100644
--- a/asmcomp/cmmgen.ml
+++ b/asmcomp/cmmgen.ml
@@ -373,9 +373,10 @@ let rec div_int c1 c2 is_safe dbg =
Cop(Cdivi, [c1; c2])
| (c1, c2) ->
bind "divisor" c2 (fun c2 ->
- Cifthenelse(c2,
- Cop(Cdivi, [c1; c2]),
- raise_symbol dbg "caml_exn_Division_by_zero"))
+ bind "dividend" c1 (fun c1 ->
+ Cifthenelse(c2,
+ Cop(Cdivi, [c1; c2]),
+ raise_symbol dbg "caml_exn_Division_by_zero")))
let mod_int c1 c2 is_safe dbg =
match (c1, c2) with
@@ -411,9 +412,10 @@ let mod_int c1 c2 is_safe dbg =
Cop(Cmodi, [c1; c2])
| (c1, c2) ->
bind "divisor" c2 (fun c2 ->
- Cifthenelse(c2,
- Cop(Cmodi, [c1; c2]),
- raise_symbol dbg "caml_exn_Division_by_zero"))
+ bind "dividend" c1 (fun c1 ->
+ Cifthenelse(c2,
+ Cop(Cmodi, [c1; c2]),
+ raise_symbol dbg "caml_exn_Division_by_zero")))
(* Division or modulo on boxed integers. The overflow case min_int / -1
can occur, in which case we force x / -1 = -x and x mod -1 = 0. (PR#5513). *)
diff --git a/testsuite/tests/basic/pr7533.ml b/testsuite/tests/basic/pr7533.ml
new file mode 100644
index 0000000000..47bbeeea9e
--- /dev/null
+++ b/testsuite/tests/basic/pr7533.ml
@@ -0,0 +1,19 @@
+(* PR#7533 *)
+
+exception Foo
+
+let f x =
+ if x > 42 then 1
+ else raise Foo
+
+let () =
+ let f = Sys.opaque_identity f in
+ match (f 0) / (List.hd (Sys.opaque_identity [0])) with
+ | exception Foo -> ()
+ | _ -> assert false
+
+let () =
+ let f = Sys.opaque_identity f in
+ match (f 0) mod (List.hd (Sys.opaque_identity [0])) with
+ | exception Foo -> ()
+ | _ -> assert false
diff --git a/testsuite/tests/basic/pr7533.reference b/testsuite/tests/basic/pr7533.reference
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/testsuite/tests/basic/pr7533.reference