Skip to content

Commit 36423d5

Browse files
committed
Add more test cases
1 parent 9145637 commit 36423d5

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/clangsa/GCChecker.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
// * if f(x) returns a derived pointer from x, a = f(x); b = f(x); PTR_PIN(a); The checker will NOT find b as pinned.
88
// * a = x->y; b = x->y; PTR_PIN(a); The checker will find b as pinned.
99
// * Need to see if this affects correctness.
10+
// * The checker may report some vals as moved even if there is a new load for the val after safepoint.
11+
// * f(x->a); jl_safepoint(); f(x->a); x->a is loaded after a safepoint, but the checker may report errors. This seems fine, as the compiler may hoist the load.
12+
// * a = x->a; f(a); jl_safepoint(); f(a); a may be moved in a safepoint, and the checker will report errors.
1013

1114
#include "clang/Frontend/FrontendActions.h"
1215
#include "clang/StaticAnalyzer/Checkers/SValExplainer.h"
@@ -46,7 +49,7 @@ static const Stmt *getStmtForDiagnostics(const ExplodedNode *N)
4649
}
4750

4851
// Turn on/off the log here
49-
#define DEBUG_LOG 0
52+
#define DEBUG_LOG 1
5053

5154
class GCChecker
5255
: public Checker<
@@ -235,7 +238,6 @@ class GCChecker
235238
: "Error");
236239
llvm::dbgs() << ",Depth=";
237240
llvm::dbgs() << RootedAtDepth;
238-
llvm::dbgs() << "\n";
239241
}
240242
};
241243

@@ -1928,6 +1930,7 @@ void GCChecker::checkBind(SVal LVal, SVal RVal, const clang::Stmt *S,
19281930
log("- No Sym");
19291931
return;
19301932
}
1933+
logWithDump("- Sym", Sym);
19311934
const auto *RootState = State->get<GCRootMap>(R);
19321935
logWithDump("- R", R);
19331936
logWithDump("- RootState for R", RootState);
@@ -1941,6 +1944,7 @@ void GCChecker::checkBind(SVal LVal, SVal RVal, const clang::Stmt *S,
19411944
} else {
19421945
logWithDump("- getValStateForRegion", R);
19431946
ValSP = getValStateForRegion(C.getASTContext(), State, R);
1947+
logWithDump("- getValStateForRegion", ValSP);
19441948
}
19451949
if (ValSP && ValSP->isRooted()) {
19461950
logWithDump("- Found base region that is rooted", ValSP);

test/clangsa/MissingPinning.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,24 @@ void mtable(jl_value_t *f) {
123123
look_at_value(mtable);
124124
PTR_UNPIN(mtable);
125125
}
126+
127+
void pass_arg_to_non_safepoint(jl_tupletype_t *sigt) {
128+
jl_value_t *ati = jl_tparam(sigt, 0);
129+
}
130+
131+
// Though the code loads the pointer after the safepoint, we don't know if the compiler would hoist the load before the safepoint.
132+
// So it is fine that the checker reports this as an error.
133+
void load_new_pointer_after_safepoint(jl_tupletype_t *t) {
134+
jl_value_t *a0 = jl_svecref(((jl_datatype_t*)(t))->parameters, 0);//expected-note{{Started tracking value here}}
135+
jl_safepoint();
136+
jl_value_t *a1 = jl_svecref(((jl_datatype_t*)(t))->parameters, 1);//expected-warning{{Argument value may have been moved}}
137+
//expected-note@-1{{Argument value may have been moved}}
138+
}
139+
140+
void hoist_load_before_safepoint(jl_tupletype_t *t) {
141+
jl_svec_t* params = ((jl_datatype_t*)(t))->parameters; //expected-note{{Started tracking value here}}
142+
jl_value_t *a0 = jl_svecref(params, 0);
143+
jl_safepoint();
144+
jl_value_t *a1 = jl_svecref(params, 1); //expected-warning{{Argument value may have been moved}}
145+
//expected-note@-1{{Argument value may have been moved}}
146+
}

0 commit comments

Comments
 (0)