<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/58134>58134</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            The OCaml bindings heavily use naked pointers, which have been deprecated in OCaml 4.11 and will not be supported in OCaml 5
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          alan-j-hu
      </td>
    </tr>
</table>

<pre>
    When modifying the LLVM OCaml bindings, I noticed that the code uses naked pointers (pointers to memory outside the OCaml heap that are not wrapped in a special block). For just one example, see

https://github.com/llvm/llvm-project/blob/0a9756fc15c57dc94146e65d251d7a3d941ae78a/llvm/bindings/ocaml/llvm/llvm_ocaml.c#L203

An `LLVMContextRef` is directly returned.

[Since OCaml 4.11, naked pointers have been deprecated. They will not be supported in OCaml 5](https://v2.ocaml.org/manual/intfc.html#ss:c-outside-head), which will move to a new runtime. The recommended solution is to either wrap the pointer in an OCaml block (heap allocation) with an `Abstract_tag` or `Custom_tag`; the GC will not scan the elements of these blocks.

Furthermore, the LLVM bindings contain many resource cleanup functions, such as https://github.com/llvm/llvm-project/blob/0a9756fc15c57dc94146e65d251d7a3d941ae78a/llvm/bindings/ocaml/llvm/llvm.mli#L454 among many others. OCaml blocks with the `Custom_tag` [support finalization functions](https://v2.ocaml.org/manual/intfc.html#s%3Ac-custom). It would be worth it to make use of this feature if removing naked pointers.

I am willing to rewrite the OCaml bindings to use blocks instead of naked pointers, but this is a rather big task, so I wanted to post an issue first and hear the input of LLVM experts. I know that the OCaml OPAM maintainers manually track package build status, so they might also be interested.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzNVMlu3DgU_Br1hbCgtZeDDo4DDww4yGAmmBwDinpq0aZIgYvbnq-fIuWtkwEGyWmARkukyLdU1aveDE_d14k0m80gxyepj8xPxG5v__rEP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