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

Miscompilation under 4.14+flambda #36

Closed
yforster opened this issue Oct 19, 2023 · 1 comment
Closed

Miscompilation under 4.14+flambda #36

yforster opened this issue Oct 19, 2023 · 1 comment

Comments

@yforster
Copy link
Contributor

The spec asks to file a report If a program runs to completion in the interpreter producing a result, it is a bug in Malfunction if the compiled version of the same program either crashes or produces a different value

I have such a situation: a program (obtained through extraction from Coq):

compare : bytestring -> bytestring -> comparison

with string from https://github.com/MetaCoq/metacoq/blob/coq-8.16/utils/theories/bytestring.v#L32 and type comparison = Eq | Lt | Gt.

Running compare "" "diff" correctly yields 1 (corresponding to Lt) in the interpreter. The compiled program yields

  • Lt on OCaml 4.13
  • Lt on OCaml 4.13+flambda
  • Lt on OCaml 4.14, and
  • Gt on OCaml 4.14+flambda

inspecting the actual value using Obj tools shows that the return value is not really 2 (Gt), but the full string "diff".

See https://github.com/yforster/malfunction-malfunctioning/actions/runs/6533871602/job/17739907316

The error can alternatively be circumvented by disabling optimisation passes in malfunction cmx (the linked repository uses a patched version where optimisation has to be explicitly enabled via malfunction cmx -O2).

@stedolan
Copy link
Owner

stedolan commented Nov 6, 2023

Thanks for reporting this! This is absolutely a bug. I've just pushed a fix with an explanation in the commit message - the short version is that the Lifthenelse constructor of Lambda in 4.14 has stricter requirements of its input than 4.13 does. Malfunction copied an optimisation from OCaml but its copy wasn't updated to meet the stricter requirements, causing miscompilation in weird cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants