r268773 - [analyzer] Add tests for Objective-C class properties

Devin Coughlin via cfe-commits cfe-commits at lists.llvm.org
Fri May 6 11:24:50 PDT 2016


Author: dcoughlin
Date: Fri May  6 13:24:50 2016
New Revision: 268773

URL: http://llvm.org/viewvc/llvm-project?rev=268773&view=rev
Log:
[analyzer] Add tests for Objective-C class properties

Add basic tests to ensure the analyzer has support for class properties. This
is a test-only change.

rdar://problem/25256807

Modified:
    cfe/trunk/test/Analysis/properties.m

Modified: cfe/trunk/test/Analysis/properties.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/properties.m?rev=268773&r1=268772&r2=268773&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/properties.m (original)
+++ cfe/trunk/test/Analysis/properties.m Fri May  6 13:24:50 2016
@@ -384,6 +384,114 @@ void testConsistencyAssign(Person *p) {
 #endif
 @end
 
+//------
+// class properties
+//------
+
+int gBackingForReadWriteClassProp = 0;
+
+ at interface ClassWithClassProperties
+ at property(class, readonly) int readOnlyClassProp;
+
+ at property(class) int readWriteClassProp;
+
+// Make sure we handle when a class and instance property have the same
+// name. Test both when instance comes first and when class comes first.
+ at property(readonly) int classAndInstancePropWithSameNameOrderInstanceFirst;
+ at property(class, readonly) int classAndInstancePropWithSameNameOrderInstanceFirst;
+
+ at property(class, readonly) int classAndInstancePropWithSameNameOrderClassFirst;
+ at property(readonly) int classAndInstancePropWithSameNameOrderClassFirst;
+
+
+ at property(class, readonly) int dynamicClassProp;
+
+ at end
+
+ at interface ClassWithClassProperties (OtherTranslationUnit)
+ at property(class, assign) id propInOtherTranslationUnit;
+ at end
+
+ at implementation ClassWithClassProperties
+
+ at dynamic dynamicClassProp;
+
++ (int)readOnlyClassProp {
+  return 1;
+}
+
++ (int)readWriteClassProp {
+  return gBackingForReadWriteClassProp;
+}
+
++ (void)setReadWriteClassProp:(int)val {
+  gBackingForReadWriteClassProp = val;
+}
+
+- (int)classAndInstancePropWithSameNameOrderInstanceFirst {
+  return 12;
+}
+
++ (int)classAndInstancePropWithSameNameOrderInstanceFirst {
+  return 13;
+}
+
++ (int)classAndInstancePropWithSameNameOrderClassFirst {
+  return 14;
+}
+
+- (int)classAndInstancePropWithSameNameOrderClassFirst {
+  return 15;
+}
+
+- (void)testInlineClassProp {
+  clang_analyzer_eval(ClassWithClassProperties.readOnlyClassProp == 1); // expected-warning{{TRUE}}
+
+  ClassWithClassProperties.readWriteClassProp = 7;
+  clang_analyzer_eval(ClassWithClassProperties.readWriteClassProp == 7); // expected-warning{{TRUE}}
+  ClassWithClassProperties.readWriteClassProp = 8;
+  clang_analyzer_eval(ClassWithClassProperties.readWriteClassProp == 8); // expected-warning{{TRUE}}
+}
+
+- (void)testUnknownClassProp {
+  clang_analyzer_eval(ClassWithClassProperties.propInOtherTranslationUnit == ClassWithClassProperties.propInOtherTranslationUnit); // expected-warning{{UNKNOWN}}
+}
+
+- (void)testEscapeGlobalOnUnknownProp {
+  gBackingForReadWriteClassProp = 33;
+  ClassWithClassProperties.propInOtherTranslationUnit = 0;
+  clang_analyzer_eval(gBackingForReadWriteClassProp == 33); // expected-warning{{UNKNOWN}}
+}
+
+- (void)testClassAndInstancePropertyWithSameName {
+  clang_analyzer_eval(self.classAndInstancePropWithSameNameOrderInstanceFirst == 12); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ClassWithClassProperties.classAndInstancePropWithSameNameOrderInstanceFirst == 13); // expected-warning{{TRUE}}
+
+  clang_analyzer_eval(ClassWithClassProperties.classAndInstancePropWithSameNameOrderClassFirst == 14); // expected-warning{{TRUE}}
+  clang_analyzer_eval(self.classAndInstancePropWithSameNameOrderClassFirst == 15); // expected-warning{{TRUE}}
+}
+
+- (void)testDynamicClassProp {
+  clang_analyzer_eval(ClassWithClassProperties.dynamicClassProp == 16); // expected-warning{{UNKNOWN}}
+}
+
+ at end
+
+ at interface SubclassOfClassWithClassProperties : ClassWithClassProperties
+ at end
+
+ at implementation SubclassOfClassWithClassProperties
++ (int)dynamicClassProp; {
+ return 16;
+}
+
+- (void)testDynamicClassProp {
+  clang_analyzer_eval(SubclassOfClassWithClassProperties.dynamicClassProp == 16); // expected-warning{{TRUE}}
+}
+
+ at end
+
+
 #if !__has_feature(objc_arc)
 void testOverrelease(Person *p, int coin) {
   switch (coin) {




More information about the cfe-commits mailing list