aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2010-02-23 21:19:33 +0000
committerTed Kremenek <kremenek@apple.com>2010-02-23 21:19:33 +0000
commit891322002b5f5886d812f6e8df12174fb2d8e73b (patch)
tree7123cea278aa2b8039afd01231387d83dabf2ce4
parent32141c8f69a6a51d7cf95a18229cd335ecd59903 (diff)
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>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96985 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Checker/CheckDeadStores.cpp3
-rw-r--r--test/Analysis/dead-stores.m7
2 files changed, 9 insertions, 1 deletions
diff --git a/lib/Checker/CheckDeadStores.cpp b/lib/Checker/CheckDeadStores.cpp
index 4a7ca70548..31f9390e62 100644
--- a/lib/Checker/CheckDeadStores.cpp
+++ b/lib/Checker/CheckDeadStores.cpp
@@ -142,7 +142,8 @@ public:
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;
diff --git a/test/Analysis/dead-stores.m b/test/Analysis/dead-stores.m
index 765a24a3c3..701e5802b2 100644
--- a/test/Analysis/dead-stores.m
+++ b/test/Analysis/dead-stores.m
@@ -34,3 +34,10 @@ void DeadStoreTest(NSObject *anObject) {
([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);
+}