Skip to content

Commit

Permalink
Fix a GC bug in local stack scanning (ocaml-flambda#17)
Browse files Browse the repository at this point in the history
The stack pointer was computed relative to the wrong local arena
  • Loading branch information
stedolan authored Apr 20, 2022
1 parent 9f879de commit b05519f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion runtime/roots_nat.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ static void do_local_allocations(caml_local_arenas* loc,
if (marked_local) {
int ix = get_local_ix(loc, *p);
struct caml_local_arena a = loc->arenas[ix];
intnat newsp = (char*)p - (a.base + a.length);
intnat newsp = (char*)*p - (a.base + a.length);
if (sp <= newsp) {
/* forwards pointer, common case */
CAMLassert(ix <= arena_ix);
Expand Down
20 changes: 20 additions & 0 deletions testsuite/tests/typing-local/localgcbug.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(* TEST
flags += "-extension local"
* native *)

type n = Z | S of n

let rec gen_locals (local_ n) depth _ = local_
if depth = 0
then
S n
else
let s = S n in
let m = gen_locals s (depth - 1) (ref 42) in
let _ = gen_locals m (depth - 1) (ref 42) in
S n

let () =
match gen_locals Z 21 (ref 42) with
| S Z -> print_endline "ok"
| _ -> assert false
1 change: 1 addition & 0 deletions testsuite/tests/typing-local/localgcbug.reference
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ok

0 comments on commit b05519f

Please sign in to comment.