Polish diagnostics for null dereferences via ObjC ivar accesses. Finishes up <rdar://problem/6352035>.
llvm-svn: 113612
This commit is contained in:
parent
b57a127a53
commit
0a3f523614
|
@ -123,6 +123,19 @@ void DereferenceChecker::VisitLocation(CheckerContext &C, const Stmt *S,
|
|||
}
|
||||
break;
|
||||
}
|
||||
case Stmt::ObjCIvarRefExprClass: {
|
||||
const ObjCIvarRefExpr *IV = cast<ObjCIvarRefExpr>(S);
|
||||
if (const DeclRefExpr *DR =
|
||||
dyn_cast<DeclRefExpr>(IV->getBase()->IgnoreParenCasts())) {
|
||||
if (const VarDecl *VD = dyn_cast<VarDecl>(DR->getDecl())) {
|
||||
llvm::raw_svector_ostream os(buf);
|
||||
os << "Instance variable access (via '" << VD->getName()
|
||||
<< "') results in a null pointer dereference";
|
||||
}
|
||||
}
|
||||
Ranges.push_back(IV->getSourceRange());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1110,3 +1110,22 @@ void rdar6351970_c() {
|
|||
@synchronized(x) {} // expected-warning{{Uninitialized value used as mutex for @synchronized}}
|
||||
}
|
||||
|
||||
// <rdar://problem/6352035> rule request: direct structure member access null pointer dereference
|
||||
@interface RDar6352035 {
|
||||
int c;
|
||||
}
|
||||
- (void)foo;
|
||||
- (void)bar;
|
||||
@end
|
||||
|
||||
@implementation RDar6352035
|
||||
- (void)foo {
|
||||
RDar6352035 *friend = 0;
|
||||
friend->c = 7; // expected-warning{{Instance variable access (via 'friend') results in a null pointer dereference}}
|
||||
}
|
||||
- (void)bar {
|
||||
self = 0;
|
||||
c = 7; // expected-warning{{Instance variable access (via 'self') results in a null pointer dereference}}
|
||||
}
|
||||
@end
|
||||
|
||||
|
|
Loading…
Reference in New Issue