[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)
llvm-svn: 165992

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

index 8646829..dc90b67 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 2311ef2..87ab7f7 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;