mirror of
https://github.com/intel/llvm.git
synced 2026-02-09 01:52:26 +08:00
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>. llvm-svn: 96985
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user