[cfe-commits] r172766 - in /cfe/trunk: lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp test/Analysis/objc/direct-ivar-assignment-in-annotated-functions.m
Anna Zaks
ganna at apple.com
Thu Jan 17 15:24:58 PST 2013
Author: zaks
Date: Thu Jan 17 17:24:58 2013
New Revision: 172766
URL: http://llvm.org/viewvc/llvm-project?rev=172766&view=rev
Log:
[analyzer] DirectIvarAssignment: allow suppression annotation on Ivars.
Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp
cfe/trunk/test/Analysis/objc/direct-ivar-assignment-in-annotated-functions.m
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp?rev=172766&r1=172765&r2=172766&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp Thu Jan 17 17:24:58 2013
@@ -7,9 +7,17 @@
//
//===----------------------------------------------------------------------===//
//
-// Check that Objective C properties follow the following rules:
-// - The property should be set with the setter, not though a direct
-// assignment.
+// Check that Objective C properties are set with the setter, not though a
+// direct assignment.
+//
+// Two versions of a checker exist: one that checks all methods and the other
+// that only checks the methods annotated with
+// __attribute__((annotate("objc_no_direct_instance_variable_assignment")))
+//
+// The checker does not warn about assignments to Ivars, annotated with
+// __attribute__((objc_allow_direct_instance_variable_assignment"))). This
+// annotation serves as a false positive suppression mechanism for the
+// checker. The annotation is allowed on properties and Ivars.
//
//===----------------------------------------------------------------------===//
@@ -155,7 +163,7 @@
}
}
-static bool isAnnotatedToAllowDirectAssignment(const ObjCPropertyDecl *D) {
+static bool isAnnotatedToAllowDirectAssignment(const Decl *D) {
for (specific_attr_iterator<AnnotateAttr>
AI = D->specific_attr_begin<AnnotateAttr>(),
AE = D->specific_attr_end<AnnotateAttr>(); AI != AE; ++AI) {
@@ -183,10 +191,12 @@
if (I != IvarToPropMap.end()) {
const ObjCPropertyDecl *PD = I->second;
- // Skip warnings on Ivars that correspond to properties, annotated with
+ // Skip warnings on Ivars, annotated with
// objc_allow_direct_instance_variable_assignment. This annotation serves
- // as a false positive suppression mechanism for the checker.
- if (isAnnotatedToAllowDirectAssignment(PD))
+ // as a false positive suppression mechanism for the checker. The
+ // annotation is allowed on properties and ivars.
+ if (isAnnotatedToAllowDirectAssignment(PD) ||
+ isAnnotatedToAllowDirectAssignment(D))
return;
ObjCMethodDecl *GetterMethod =
Modified: cfe/trunk/test/Analysis/objc/direct-ivar-assignment-in-annotated-functions.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/objc/direct-ivar-assignment-in-annotated-functions.m?rev=172766&r1=172765&r2=172766&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/objc/direct-ivar-assignment-in-annotated-functions.m (original)
+++ cfe/trunk/test/Analysis/objc/direct-ivar-assignment-in-annotated-functions.m Thu Jan 17 17:24:58 2013
@@ -23,6 +23,7 @@
@interface TestProperty : AnnotatedClass {
MyClass *_Z;
id _nonSynth;
+ MyClass* _NotA __attribute__((annotate("objc_allow_direct_instance_variable_assignment")));
}
@property (assign, nonatomic) MyClass* A; // explicitely synthesized, not implemented, non-default ivar name
@@ -33,7 +34,8 @@
@property (assign, nonatomic) MyClass* Z; // non synthesized ivar, implemented setter
@property (readonly) id nonSynth; // non synthesized, explicitly implemented to return ivar with expected name
-
+
+ @property (assign) MyClass* NotA; // warnings should be suppressed, backing ivar is annotated
@property (assign) MyClass* NotX __attribute__((annotate("objc_allow_direct_instance_variable_assignment"))); // warnings should be suppressed
@end
@@ -48,6 +50,7 @@
_Z = In; // expected-warning {{Direct assignment to an instance variable backing a property; use the setter instead}}
_nonSynth = 0; // expected-warning {{Direct assignment to an instance variable backing a property; use the setter instead}}
_NotX = 0; // no-warning
+ _NotA = 0; // no-warning
}
- (void) someMethodNotAnnaotated: (MyClass*)In {
(__A) = In;
More information about the cfe-commits
mailing list