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

Left-shift of 0 yields negative number #8864

Closed
murilogiacometti opened this issue Aug 8, 2019 · 6 comments · Fixed by #8865

Comments

@murilogiacometti
Copy link

commented Aug 8, 2019

Compilation

ocamlopt -O3 -w -5-26 error.ml
ocamlc -w -5-26 error.ml

Program (error.ml)

let (i:int) = (lsl) (compare 0 0) 63 in print_int i

Output - Bytecode (ocamlc)

0

Output - Native (ocamlopt)

-4611686018427387904

Environment

environment       ocaml-base-compiler.4.08.0
ocamlc            4.08.0
ocamlopt          4.08.0
architecture/OS   x86_64 GNU/Linux

Issue found with https://github.com/jmid/efftester

@hcarty

This comment has been minimized.

Copy link
Contributor

commented Aug 8, 2019

I get the same result with OCaml 4.07.1 on macos.

If compare 0 0 is replaced by a literal 0 then the output is 0 when using ocamlopt.

@lthls

This comment has been minimized.

Copy link
Contributor

commented Aug 8, 2019

I can reproduce, the bug has been here since the merge of #17.
The problem is that lsl (-1) 63 gives 0 (both on bytecode and native, as expected) but Misc.no_overflow_lsl (-1) 63 returns true.
I'll submit a fix.

@lthls

This comment has been minimized.

Copy link
Contributor

commented Aug 8, 2019

@murilogiacometti could you precise what setup of the compiler you're testing ?
It is possible that your compiler is compiled without flambda support, which means that the -O3 option is ignored. If you have the opportunity, it could be interesting to compare not only ocamlc and ocamlopt but also an flambda-enabled ocamlopt (to which you could pass the -O3 option if you wish).
Thanks for the report anyway.

@hcarty

This comment has been minimized.

Copy link
Contributor

commented Aug 8, 2019

FWIW, my test on macos was with a default/non-flambda ocamlopt.

@lthls

This comment has been minimized.

Copy link
Contributor

commented Aug 8, 2019

(Both flambda and non-flambda are affected, but since this bug was found with the help of an automated tool, testing more configurations could find more bugs)

@xavierleroy

This comment has been minimized.

Copy link
Contributor

commented Aug 9, 2019

Fixed by #8865. Commits: trunk 0557f07, 4.09 bd31ecb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.