Skip to content

Commit b05519f

Browse files
authored
Fix a GC bug in local stack scanning (#17)
The stack pointer was computed relative to the wrong local arena
1 parent 9f879de commit b05519f

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

runtime/roots_nat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ static void do_local_allocations(caml_local_arenas* loc,
522522
if (marked_local) {
523523
int ix = get_local_ix(loc, *p);
524524
struct caml_local_arena a = loc->arenas[ix];
525-
intnat newsp = (char*)p - (a.base + a.length);
525+
intnat newsp = (char*)*p - (a.base + a.length);
526526
if (sp <= newsp) {
527527
/* forwards pointer, common case */
528528
CAMLassert(ix <= arena_ix);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
(* TEST
2+
flags += "-extension local"
3+
* native *)
4+
5+
type n = Z | S of n
6+
7+
let rec gen_locals (local_ n) depth _ = local_
8+
if depth = 0
9+
then
10+
S n
11+
else
12+
let s = S n in
13+
let m = gen_locals s (depth - 1) (ref 42) in
14+
let _ = gen_locals m (depth - 1) (ref 42) in
15+
S n
16+
17+
let () =
18+
match gen_locals Z 21 (ref 42) with
19+
| S Z -> print_endline "ok"
20+
| _ -> assert false
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ok

0 commit comments

Comments
 (0)