[cfe-commits] r96985 - in /cfe/trunk: lib/Checker/CheckDeadStores.cpp test/Analysis/dead-stores.m
Ted Kremenek
kremenek at apple.com
Tue Feb 23 13:19:33 PST 2010
Author: kremenek
Date: Tue Feb 23 15:19:33 2010
New Revision: 96985
URL: http://llvm.org/viewvc/llvm-project?rev=96985&view=rev
Log:
Dead emit dead store warnings when assigning nil to an ObjC object
pointer (for defensive programming). This matches the behavior with
assigning NULL to a regular pointer. Fixes <rdar://problem/7631278>.
Modified:
cfe/trunk/lib/Checker/CheckDeadStores.cpp
cfe/trunk/test/Analysis/dead-stores.m
Modified: cfe/trunk/lib/Checker/CheckDeadStores.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/CheckDeadStores.cpp?rev=96985&r1=96984&r2=96985&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/CheckDeadStores.cpp (original)
+++ cfe/trunk/lib/Checker/CheckDeadStores.cpp Tue Feb 23 15:19:33 2010
@@ -142,7 +142,8 @@
if (VarDecl *VD = dyn_cast<VarDecl>(DR->getDecl())) {
// Special case: check for assigning null to a pointer.
// This is a common form of defensive programming.
- if (VD->getType()->isPointerType()) {
+ QualType T = VD->getType();
+ if (T->isPointerType() || T->isObjCObjectPointerType()) {
if (B->getRHS()->isNullPointerConstant(Ctx,
Expr::NPC_ValueDependentIsNull))
return;
Modified: cfe/trunk/test/Analysis/dead-stores.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/dead-stores.m?rev=96985&r1=96984&r2=96985&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/dead-stores.m (original)
+++ cfe/trunk/test/Analysis/dead-stores.m Tue Feb 23 15:19:33 2010
@@ -34,3 +34,10 @@
([keys containsObject:@"name"] && [keys containsObject:@"icon"])) {}
}
+// This test case was a false positive due to how clang models
+// pointer types and ObjC object pointer types differently. Here
+// we don't warn about a dead store because 'nil' is assigned to
+// an object pointer for the sake of defensive programming.
+void rdar_7631278(NSObject *x) {
+ x = ((void*)0);
+}
More information about the cfe-commits
mailing list