Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Wrong code generation of e / e' and e mod e' with effectful e #7533
Original bug ID: 7533
Consider the examples
(int_of_string "") / (let e = let w = false in () in 0)
At runtime the dividend throws an exception and the divisor evaluates to 0.
Fatal error: exception Failure("int_of_string")
However with the native code backend I get:
Fatal error: exception Division_by_zero
thereby removing the effect of the dividend.
I believe the problem is in asmcomp/cmmgen.ml, line 410-414,
| (c1, c2) ->
Note how c1 never gets evaluated when we branch on the result of c2 and it is 0.
There is a similar problem with 'mod' (replacing '/' with 'mod' in the examples):
(int_of_string "") mod (let e = let w = false in () in 0)
and the code generation case for mod in asmcomp/cmmgen.ml, line 446-450.
This is confirmed and reproducable on version 4.04.1 under Debian and 4.04.0 under OSX.
Steps to reproduce
$ echo '(int_of_string "") / (let e = let w = false in () in 0)' > div.ml
$ echo '(int_of_string "") mod (let e = let w = false in () in 0)' > mod.ml