Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
ocamlopt returns n for (n mod 1) instead of 0 #6749
Original bug ID: 6749
The code is "let () = for i = 1 to 3 do Printf.printf "%d\n" (i mod 1) done".
The results of the code with ocamlopt are:
but it should be:
I think that mod_int in asmcomp/cmmgen.ml may have a bug.
Comment author: @gasche
Indeed this is a bug in cmmgen.ml:mod_int which believes that (c1 mod 1 = c1) instead of (c1 mod 1 = 0). This was introduced by commit trunk@14303 between 4.01 and 4.02 (3bb1612), and it seems to be a copy-pasting mistake from div_int's definition.
The whole function should be reviewed (it also seems to believe that (1 mod n = 1)), and it would also be important to understand why the testsuite that was added for #6042 did not catch this bug.
Comment author: pcouderc
"List.iter (fun x -> Printf.printf "%d\n" (x mod 1)) [1; 2; 3]"
produces the same result, however unrolling it, i.e.
"Printf.printf "%d\n" (1 mod 1);
returns a correct result.
Comment author: @mshinwell
Proposed patch attached; comments welcome.
We couldn't see anything else wrong.