diff options
author | Anna Zaks <ganna@apple.com> | 2013-01-16 01:36:00 +0000 |
---|---|---|
committer | Anna Zaks <ganna@apple.com> | 2013-01-16 01:36:00 +0000 |
commit | d7b1d2467d8bf01be5068dbbad1a6324cee8bf4a (patch) | |
tree | e82e6d5f223f85db382a051377292dde8a8bbd19 /lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp | |
parent | 79ccd5635495fb4588d0ec47c0bf05764441a14c (diff) |
[analyzer] Add an annotation to allow suppression of direct ivar
assignment
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172597 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp')
-rw-r--r-- | lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp b/lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp index 378c175338..2cb511cbea 100644 --- a/lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp +++ b/lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp @@ -155,6 +155,18 @@ void DirectIvarAssignment::checkASTDecl(const ObjCImplementationDecl *D, } } +static bool isAnnotatedToAllowDirectAssignment(const ObjCPropertyDecl *D) { + for (specific_attr_iterator<AnnotateAttr> + AI = D->specific_attr_begin<AnnotateAttr>(), + AE = D->specific_attr_end<AnnotateAttr>(); AI != AE; ++AI) { + const AnnotateAttr *Ann = *AI; + if (Ann->getAnnotation() == + "objc_allow_direct_instance_variable_assignment") + return true; + } + return false; +} + void DirectIvarAssignment::MethodCrawler::VisitBinaryOperator( const BinaryOperator *BO) { if (!BO->isAssignmentOp()) @@ -168,8 +180,14 @@ void DirectIvarAssignment::MethodCrawler::VisitBinaryOperator( if (const ObjCIvarDecl *D = IvarRef->getDecl()) { IvarToPropertyMapTy::const_iterator I = IvarToPropMap.find(D); + if (I != IvarToPropMap.end()) { const ObjCPropertyDecl *PD = I->second; + // Skip warnings on Ivars that correspond to properties, annotated with + // objc_allow_direct_instance_variable_assignment. This annotation serves + // as a false positive suppression mechanism for the checker. + if (isAnnotatedToAllowDirectAssignment(PD)) + return; ObjCMethodDecl *GetterMethod = InterfD->getInstanceMethod(PD->getGetterName()); |