Skip to content

Commit b48315d

Browse files
authored
Merge pull request #104 from haoNoQ/static-analyzer-cherrypicks-2
Static analyzer cherrypicks 2
2 parents dc6e877 + cb0f08c commit b48315d

File tree

3 files changed

+73
-15
lines changed

3 files changed

+73
-15
lines changed

clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,14 +1418,19 @@ FindLastStoreBRVisitor::VisitNode(const ExplodedNode *Succ,
14181418
if (Optional<CallEnter> CE = Succ->getLocationAs<CallEnter>()) {
14191419
if (const auto *VR = dyn_cast<VarRegion>(R)) {
14201420

1421-
const auto *Param = cast<ParmVarDecl>(VR->getDecl());
1421+
if (const auto *Param = dyn_cast<ParmVarDecl>(VR->getDecl())) {
1422+
ProgramStateManager &StateMgr = BRC.getStateManager();
1423+
CallEventManager &CallMgr = StateMgr.getCallEventManager();
14221424

1423-
ProgramStateManager &StateMgr = BRC.getStateManager();
1424-
CallEventManager &CallMgr = StateMgr.getCallEventManager();
1425-
1426-
CallEventRef<> Call = CallMgr.getCaller(CE->getCalleeContext(),
1427-
Succ->getState());
1428-
InitE = Call->getArgExpr(Param->getFunctionScopeIndex());
1425+
CallEventRef<> Call = CallMgr.getCaller(CE->getCalleeContext(),
1426+
Succ->getState());
1427+
InitE = Call->getArgExpr(Param->getFunctionScopeIndex());
1428+
} else {
1429+
// Handle Objective-C 'self'.
1430+
assert(isa<ImplicitParamDecl>(VR->getDecl()));
1431+
InitE = cast<ObjCMessageExpr>(CE->getCalleeContext()->getCallSite())
1432+
->getInstanceReceiver()->IgnoreParenCasts();
1433+
}
14291434
IsParam = true;
14301435
}
14311436
}
@@ -2029,8 +2034,6 @@ bool bugreporter::trackExpressionValue(const ExplodedNode *InputNode,
20292034

20302035
// Is it a symbolic value?
20312036
if (auto L = V.getAs<loc::MemRegionVal>()) {
2032-
report.addVisitor(llvm::make_unique<UndefOrNullArgVisitor>(L->getRegion()));
2033-
20342037
// FIXME: this is a hack for fixing a later crash when attempting to
20352038
// dereference a void* pointer.
20362039
// We should not try to dereference pointers at all when we don't care
@@ -2051,10 +2054,14 @@ bool bugreporter::trackExpressionValue(const ExplodedNode *InputNode,
20512054
else if (CanDereference)
20522055
RVal = LVState->getSVal(L->getRegion());
20532056

2054-
if (CanDereference)
2057+
if (CanDereference) {
2058+
report.addVisitor(
2059+
std::make_unique<UndefOrNullArgVisitor>(L->getRegion()));
2060+
20552061
if (auto KV = RVal.getAs<KnownSVal>())
20562062
report.addVisitor(llvm::make_unique<FindLastStoreBRVisitor>(
20572063
*KV, L->getRegion(), EnableNullFPSuppression, TKind, SFC));
2064+
}
20582065

20592066
const MemRegion *RegionRVal = RVal.getAsRegion();
20602067
if (RegionRVal && isa<SymbolicRegion>(RegionRVal)) {

clang/test/Analysis/novoidtypecrash.c

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,27 @@
11
// RUN: %clang_analyze_cc1 -analyzer-checker=core %s
2+
x;
3+
y(void **z) { // no-crash
4+
*z = x;
5+
int *w;
6+
y(&w);
7+
*w;
8+
}
9+
210
a;
3-
b(void **c) { // no-crash
4-
*c = a;
5-
int *d;
6-
b(&d);
7-
*d;
11+
b(*c) {}
12+
e(*c) {
13+
void *d = f();
14+
b(d);
15+
*c = d;
16+
}
17+
void *g() {
18+
e(&a);
19+
return a;
20+
}
21+
j() {
22+
int h;
23+
char i = g();
24+
if (i)
25+
for (; h;)
26+
;
827
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: %clang_analyze_cc1 -w -analyzer-checker=core,nullability -verify %s
2+
3+
// expected-no-diagnostics
4+
5+
@class C;
6+
7+
#pragma clang assume_nonnull begin
8+
@interface I
9+
- foo:(C *)c;
10+
@end
11+
#pragma clang assume_nonnull end
12+
13+
@interface J
14+
@property C *c;
15+
@end
16+
17+
J *conjure_J();
18+
19+
@implementation I
20+
- (void)bar {
21+
if (self) { // no-crash
22+
J *j = conjure_J();
23+
if (j.c)
24+
[self bar];
25+
// FIXME: Should warn.
26+
[self foo:j.c]; // no-warning
27+
}
28+
}
29+
@end
30+
31+
@implementation J
32+
@end

0 commit comments

Comments
 (0)