Skip to content

Commit

Permalink
Give caml_send* arguments the correct types (#10498)
Browse files Browse the repository at this point in the history
One of the arguments is a derived pointer.  It must therefore be declared with type Addr.

The derived pointer is live throughout a loop.  If we let the Polling pass have its way, it inserts an Ipoll instruction in this loop, and the derived pointer is live across the Ipoll, which is wrong and rejected at compile-time.

We instruct the Polling pass to not add poll points to caml_send* functions, just like it does not add poll points to caml_apply* functions.  This fixes the issue and is safe, as caml_send* cannot cause an infinite loop by itself.

Co-authored-by: Vincent Laviron <vincent.laviron@gmail.com>
(cherry picked from commit e608b7c)
  • Loading branch information
xavierleroy authored and Octachron committed Jul 12, 2021
1 parent 0ae6c6a commit 20d9aef
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Changes
Expand Up @@ -579,6 +579,13 @@ OCaml 4.13.0
with -dsource
(Matt Else, review by Florian Angeletti)

- #10461, #10498: `caml_send*` helper functions take derived pointers
as arguments. Those must be declared with type Addr instead of Val.
Moreover, poll point insertion must be disabled for `caml_send*`,
otherwise the derived pointer is live across a poll point.
(Vincent Laviron and Xavier Leroy, review by Xavier Leroy and Sadiq Jaffer)


OCaml 4.12, maintenance version
-------------------------------

Expand Down
2 changes: 1 addition & 1 deletion asmcomp/cmm_helpers.ml
Expand Up @@ -1865,7 +1865,7 @@ let send_function arity =
let cache = cache in
let fun_name = "caml_send" ^ Int.to_string arity in
let fun_args =
[obj, typ_val; tag, typ_int; cache, typ_val]
[obj, typ_val; tag, typ_int; cache, typ_addr]
@ List.map (fun id -> (id, typ_val)) (List.tl args) in
let fun_dbg = placeholder_fun_dbg ~human_name:fun_name in
Cfunction
Expand Down
1 change: 1 addition & 0 deletions asmcomp/polling.ml
Expand Up @@ -24,6 +24,7 @@ module String = Misc.Stdlib.String

let function_is_assumed_to_never_poll func =
String.starts_with ~prefix:"caml_apply" func
|| String.starts_with ~prefix:"caml_send" func

(* Detection of recursive handlers that are not guaranteed to poll
at every loop iteration. *)
Expand Down

0 comments on commit 20d9aef

Please sign in to comment.