From: Anna Zaks Date: Mon, 15 Oct 2012 22:48:14 +0000 (+0000) Subject: [analyzer] Do not warn on direct ivar assignments within copy methods. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=625ce084bc8de75e74b8920593ab761f20ff5971;p=clang [analyzer] Do not warn on direct ivar assignments within copy methods. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165992 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp b/lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp index 8646829548..dc90b67e20 100644 --- a/lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp +++ b/lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp @@ -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; diff --git a/test/Analysis/objc-properties.m b/test/Analysis/objc-properties.m index 2311ef2437..87ab7f7163 100644 --- a/test/Analysis/objc-properties.m +++ b/test/Analysis/objc-properties.m @@ -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 {} ++(id)alloc; +-(id)init; +-(id)autorelease; +-(id)copy; +-(id)retain; +@end @interface MyClass; @end -@interface TestProperty { +@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;