Unsafe uses of Obj in Unmarshal
A few pieces of code in the Unmarshal
module are too obviously unsafe for the Flambda 2 compiler's taste, and results in the compiler deliberately inserting a segfault.
The Sys.opaque_identity
function can be used to tell the compiler not to make any assumptions on the underlying value, and is available since OCaml 4.03, so I'd like to see it used here to allow testing Frama C with Flambda 2.
The three places that are affected are:
- The code for initialising
arch_bigendian
. This can be fixed by inserting a call toSys.opaque_identity
. - The code for initialising
arch_float_endianness
. This can be fixed by inserting a call toSys.opaque_identity
. - The code for computing the
null
value. I assume that the code was intended to compute a null pointer, but it was reading the wrong field anyway so this was instead a pointer to a C-allocated struct (which, it seems, works as well). I'd like to replace it withObj.repr (Sys.opaque_identity (ref 0))
, which should work too (it gives you a unique static pointer) and has the advantage of not manipulating naked pointers.
I could propose a patch if you'd like (or even open a merge request, if your GitLab instance accepts merge requests from external contributors)