Skip to content

Commit 5d34086

Browse files
committed
In a few cases, we also check if value state is pinned. When it is not,
we try find ways to figure out if it is actually pinned.
1 parent bd5eb9f commit 5d34086

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

src/clangsa/GCChecker.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static const Stmt *getStmtForDiagnostics(const ExplodedNode *N)
4949
}
5050

5151
// Turn on/off the log here
52-
#define DEBUG_LOG 1
52+
#define DEBUG_LOG 0
5353

5454
class GCChecker
5555
: public Checker<
@@ -1980,7 +1980,7 @@ void GCChecker::checkBind(SVal LVal, SVal RVal, const clang::Stmt *S,
19801980
} else {
19811981
logWithDump("- Found ValState for Sym", RValState);
19821982
validateValue(RValState, C, Sym, "Trying to root value which may have been");
1983-
if (!RValState->isRooted() ||
1983+
if (!RValState->isRooted() || !RValState->isPinnedByAnyway() ||
19841984
RValState->RootDepth > RootState->RootedAtDepth) {
19851985
auto NewVS = getRootedFromRegion(R, State->get<GCPinMap>(R), RootState->RootedAtDepth);
19861986
logWithDump("- getRootedFromRegion", NewVS);
@@ -2059,7 +2059,7 @@ void GCChecker::checkLocation(SVal SLoc, bool IsLoad, const Stmt *S,
20592059
const ValueState *ValS = State->get<GCValueMap>(LoadedSym);
20602060
logWithDump("- IsLoad, LoadedSym", LoadedSym);
20612061
logWithDump("- IsLoad, ValS", ValS);
2062-
if (!ValS || !ValS->isRooted() || ValS->RootDepth > RS->RootedAtDepth) {
2062+
if (!ValS || !ValS->isRooted() || !ValS->isPinnedByAnyway() || ValS->RootDepth > RS->RootedAtDepth) {
20632063
auto NewVS = getRootedFromRegion(SLoc.getAsRegion(), State->get<GCPinMap>(SLoc.getAsRegion()), RS->RootedAtDepth);
20642064
logWithDump("- IsLoad, NewVS", NewVS);
20652065
DidChange = true;

test/clangsa/MissingPinning.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,38 @@ void hoist_load_before_safepoint(jl_tupletype_t *t) {
144144
jl_value_t *a1 = jl_svecref(params, 1); //expected-warning{{Argument value may have been moved}}
145145
//expected-note@-1{{Argument value may have been moved}}
146146
}
147+
148+
// We tpin a local var, and later rebind a value to the local val. The value should be considered as pinned.
149+
void rebind_tpin(jl_method_instance_t *mi, size_t world) {
150+
jl_code_info_t *src = NULL;
151+
JL_GC_PUSH1(&src);
152+
jl_value_t *ci = jl_rettype_inferred(mi, world, world);
153+
jl_code_instance_t *codeinst = (ci == jl_nothing ? NULL : (jl_code_instance_t*)ci);
154+
if (codeinst) {
155+
PTR_PIN(mi->def.method);
156+
PTR_PIN(codeinst);
157+
src = (jl_code_info_t*)jl_atomic_load_relaxed(&codeinst->inferred);
158+
src = jl_uncompress_ir(mi->def.method, codeinst, (jl_array_t*)src);
159+
PTR_UNPIN(codeinst);
160+
PTR_UNPIN(mi->def.method);
161+
}
162+
JL_GC_POP();
163+
}
164+
165+
void rebind_tpin_simple1() {
166+
jl_value_t *t = NULL;
167+
JL_GC_PUSH1(&t);
168+
jl_svec_t *v = jl_svec1(NULL);
169+
t = (jl_value_t*)v;
170+
look_at_value(t);
171+
JL_GC_POP();
172+
}
173+
174+
void rebind_tpin_simple2() {
175+
jl_value_t *t = NULL;
176+
JL_GC_PUSH1(&t);
177+
jl_svec_t *v = jl_svec1(NULL);
178+
t = (jl_value_t*)v;
179+
look_at_value(v);
180+
JL_GC_POP();
181+
}

0 commit comments

Comments
 (0)