]> granicus.if.org Git - clang/commitdiff
[analyzer] Do not warn on direct ivar assignments within copy methods.
authorAnna Zaks <ganna@apple.com>
Mon, 15 Oct 2012 22:48:14 +0000 (22:48 +0000)
committerAnna Zaks <ganna@apple.com>
Mon, 15 Oct 2012 22:48:14 +0000 (22:48 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165992 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp
test/Analysis/objc-properties.m

index 86468295483870d58669450eb0396cbd8211319b..dc90b67e20face2cc65fd67737bf0952f01b3853 100644 (file)
@@ -122,6 +122,8 @@ void DirectIvarAssignment::checkASTDecl(const ObjCImplementationDecl *D,
     // initialization based on their name.
     if (M->getMethodFamily() == OMF_init ||
         M->getMethodFamily() == OMF_dealloc ||
+        M->getMethodFamily() == OMF_copy ||
+        M->getMethodFamily() == OMF_mutableCopy ||
         M->getSelector().getNameForSlot(0).find("init") != StringRef::npos ||
         M->getSelector().getNameForSlot(0).find("Init") != StringRef::npos)
       continue;
index 2311ef2437cd244dacff413b44a8fa6a198a53a3..87ab7f716395cb3eedc1761b7631d2372040e38d 100644 (file)
@@ -1,8 +1,18 @@
-// RUN: %clang_cc1 -analyze -analyzer-checker=alpha.osx.cocoa.DirectIvarAssignment -fobjc-default-synthesize-properties -Wno-objc-root-class -verify -fblocks %s
+// RUN: %clang_cc1 -analyze -analyzer-checker=alpha.osx.cocoa.DirectIvarAssignment -fobjc-default-synthesize-properties -verify -fblocks %s
+
+typedef signed char BOOL;
+@protocol NSObject  - (BOOL)isEqual:(id)object; @end
+@interface NSObject <NSObject> {}
++(id)alloc;
+-(id)init;
+-(id)autorelease;
+-(id)copy;
+-(id)retain;
+@end
 
 @interface MyClass;
 @end
-@interface TestProperty {
+@interface TestProperty :NSObject {
   MyClass *_Z;
   id _nonSynth;
 }
     return self;
   }
 
+  - (id) copyWithPtrY: (TestProperty*) value {
+    TestProperty *another = [[TestProperty alloc] init];
+    another->_Y = value->_Y; // no-warning
+    return another;
+  }
+
   - (id) myInitWithPtr: (MyClass*) value {
     _Y = value; // no-warning
     return self;