Prevent inlining of CamlinternalLazy.force

master
Vincent Laviron 2020-10-30 15:02:50 +01:00
parent 45ec93e0f4
commit e78db7b6a5
2 changed files with 16 additions and 4 deletions

View File

@ -45,11 +45,12 @@ let force_val_lazy_block (blk : 'arg lazy_t) =
result
(* [force] is not used, since [Lazy.force] is declared as a primitive
whose code inlines the tag tests of its argument. This function is
here for the sake of completeness, and for debugging purpose. *)
(* [force] is not used except when afl instrumentation is on.
In this case, it must not be inlined in flambda mode as it can modify
its argument in some cases, and is allowed to be called
with immutable arguments, which will generate warning 59. *)
let force (lzv : 'arg lazy_t) =
let[@inline never] force (lzv : 'arg lazy_t) =
let x = Obj.repr lzv in
let t = Obj.tag x in
if t = Obj.forward_tag then (Obj.obj (Obj.field x 0) : 'arg) else

View File

@ -0,0 +1,11 @@
(* TEST
* flambda
** native
ocamlopt_flags = "-O3 -afl-instrument"
*)
let f l =
Lazy.force l
let _ =
Sys.opaque_identity (f (lazy "Hello"))