[cfe-commits] r113612 - in /cfe/trunk: lib/Checker/DereferenceChecker.cpp test/Analysis/misc-ps.m
Ted Kremenek
kremenek at apple.com
Fri Sep 10 13:20:50 PDT 2010
Author: kremenek
Date: Fri Sep 10 15:20:49 2010
New Revision: 113612
URL: http://llvm.org/viewvc/llvm-project?rev=113612&view=rev
Log:
Polish diagnostics for null dereferences via ObjC ivar accesses. Finishes up <rdar://problem/6352035>.
Modified:
cfe/trunk/lib/Checker/DereferenceChecker.cpp
cfe/trunk/test/Analysis/misc-ps.m
Modified: cfe/trunk/lib/Checker/DereferenceChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/DereferenceChecker.cpp?rev=113612&r1=113611&r2=113612&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/DereferenceChecker.cpp (original)
+++ cfe/trunk/lib/Checker/DereferenceChecker.cpp Fri Sep 10 15:20:49 2010
@@ -123,6 +123,19 @@
}
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;
}
Modified: cfe/trunk/test/Analysis/misc-ps.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-ps.m?rev=113612&r1=113611&r2=113612&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/misc-ps.m (original)
+++ cfe/trunk/test/Analysis/misc-ps.m Fri Sep 10 15:20:49 2010
@@ -1110,3 +1110,22 @@
@synchronized(x) {} // expected-warning{{Uninitialized value used as mutex for @synchronized}}
}
+// <rdar://problem/6352035> rule request: direct structure member access null pointer dereference
+ at interface RDar6352035 {
+ int c;
+}
+- (void)foo;
+- (void)bar;
+ at end
+
+ at 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}}
+}
+ at end
+
More information about the cfe-commits
mailing list