Skip to content

Commit b811a06

Browse files
authored
Merge pull request #32773 from JuliaLang/kf/32751
Fix missing GC root
2 parents a0936f9 + d4f3176 commit b811a06

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/builtins.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,14 +603,16 @@ JL_CALLABLE(jl_f__apply)
603603
while (next != jl_nothing) {
604604
roots[stackalloc] = next;
605605
jl_value_t *value = jl_fieldref(next, 0);
606-
roots[stackalloc + 1] = next;
606+
roots[stackalloc + 1] = value;
607607
jl_value_t *state = jl_fieldref(next, 1);
608608
roots[stackalloc] = state;
609609
_grow_to(&roots[0], &newargs, &arg_heap, &n_alloc, n + precount + 1, extra);
610+
JL_GC_ASSERT_LIVE(value);
610611
newargs[n++] = value;
611612
if (arg_heap)
612613
jl_gc_wb(arg_heap, value);
613614
roots[stackalloc + 1] = NULL;
615+
JL_GC_ASSERT_LIVE(state);
614616
args[1] = state;
615617
next = jl_apply_generic(jl_iterate_func, args, 2);
616618
}

src/julia_internal.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,16 @@ extern arraylist_t partial_inst;
10621062
#define JL_GCC_IGNORE_STOP
10631063
#endif // _COMPILER_GCC_
10641064

1065+
#ifdef __clang_analyzer__
1066+
// Not a safepoint (so it dosn't free other values), but an artificial use.
1067+
// Usually this is unnecessary because the analyzer can see all real uses,
1068+
// but sometimes real uses are harder for the analyzer to see, or it may
1069+
// give up before it sees it, so this can be helpful to be explicit.
1070+
void JL_GC_ASSERT_LIVE(jl_value_t *v) JL_NOTSAFEPOINT;
1071+
#else
1072+
#define JL_GC_ASSERT_LIVE(x) (void)(x)
1073+
#endif
1074+
10651075
#ifdef __cplusplus
10661076
}
10671077
#endif

src/support/analyzer_annotations.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,6 @@ extern "C" {
4545
#define JL_ROOTED_VALUE_COLLECTION
4646
#define JL_GC_PROMISE_ROOTED(x) (void)(x)
4747
#define jl_may_leak(x) (void)(x)
48+
#define JL_GC_ASSERT_LIVE(x)
4849

4950
#endif

0 commit comments

Comments
 (0)