[cfe-commits] r165992 - in /cfe/trunk: lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp test/Analysis/objc-properties.m

Anna Zaks ganna at apple.com
Mon Oct 15 15:48:14 PDT 2012


Author: zaks
Date: Mon Oct 15 17:48:14 2012
New Revision: 165992

URL: http://llvm.org/viewvc/llvm-project?rev=165992&view=rev
Log:
[analyzer] Do not warn on direct ivar assignments within copy methods.

Modified:
    cfe/trunk/lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp
    cfe/trunk/test/Analysis/objc-properties.m

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp?rev=165992&r1=165991&r2=165992&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp Mon Oct 15 17:48:14 2012
@@ -122,6 +122,8 @@
     // 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;

Modified: cfe/trunk/test/Analysis/objc-properties.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/objc-properties.m?rev=165992&r1=165991&r2=165992&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/objc-properties.m (original)
+++ cfe/trunk/test/Analysis/objc-properties.m Mon Oct 15 17:48:14 2012
@@ -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;
+ at protocol NSObject  - (BOOL)isEqual:(id)object; @end
+ at interface NSObject <NSObject> {}
++(id)alloc;
+-(id)init;
+-(id)autorelease;
+-(id)copy;
+-(id)retain;
+ at end
 
 @interface MyClass;
 @end
- at interface TestProperty {
+ at interface TestProperty :NSObject {
   MyClass *_Z;
   id _nonSynth;
 }
@@ -29,6 +39,12 @@
     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;





More information about the cfe-commits mailing list