Skip to content

[BUG] Miscompilation of code involving references and exceptions #1354

@vouillon

Description

@vouillon

I have found out what the block handler was for... This following piece of code is miscompiled. The issue is that the OCaml bytecode program does not allocate a reference but update the stack in place. But we no longer keep track of this update.

let x = ref 0 in
try
  incr x;
  raise Exit
with Exit ->
  Format.eprintf "%d@." !x

You have to compile it without the -g option. For instance:

ocamlc bug.ml -o bug.byte && js_of_ocaml bug.byte && ./bug.byte && node bug.js

The above command outputs 1 (correct) then 0 (wrong):

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions