]> granicus.if.org Git - clang/commitdiff
[analyzer] ObjC Inlining: add tests for ivars and properties.
authorAnna Zaks <ganna@apple.com>
Fri, 10 Aug 2012 18:56:01 +0000 (18:56 +0000)
committerAnna Zaks <ganna@apple.com>
Fri, 10 Aug 2012 18:56:01 +0000 (18:56 +0000)
TODO:
 - Handle @syncronized properties.
 - Always inline properties declared publicly (do not split the path).
This is tricky since there is no mapping from a Decl to the property in
the AST as far as I can tell.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161683 91177308-0d34-0410-b5e6-96231b3b80d8

test/Analysis/inlining/DynDispatchBifurcate.m
test/Analysis/inlining/InlineObjCInstanceMethod.h

index 2a690a5e62a2d21ad9017aec53551f9cb6c0fa93..e78b90bb8c1f840a71d8d40ca4210f5627ea1fa6 100644 (file)
 }
 @end
 
+@interface PublicClass () {
+   int value2;
+}
+@property (readwrite) int value1;
+- (void)setValue2:(int)newValue2;
+@end
+
 @implementation PublicClass
+
 - (int)getZeroPublic {
     return 0;
 }
+
+@synthesize value1;
+
+- (int)value2 {
+    return value2;
+} 
+- (void)setValue2:(int)newValue {
+    value2 = newValue;
+}
+
+- (int)value3 {
+    return value3;
+} 
+- (void)setValue3:(int)newValue {
+    value3 = newValue;
+}
+
 @end
 
 @interface MyClassWithPublicParent : PublicClass
 @end
 
 
-@interface MyClass : MyParent
+@interface MyClass : MyParent {
+  int value;
+}
 - (int)getZero;
+@property int value;
 @end
 
 // Since class is private, we assume that it cannot be subclassed.
 - (int)getZero {
     return 1;
 }
+
+- (int)value {
+  return value;
+}
+- (void)setValue:(int)newValue {
+  value = newValue;
+}
+
+// Test ivar access.
+- (int) testIvarInSelf {
+  value = 0;
+  return 5/value; // expected-warning {{Division by zero}}
+}
+
++ (int) testIvar: (MyClass*) p {
+  p.value = 0;
+  return 5/p.value; // expected-warning {{Division by zero}}
+}
+
+// Test simple property access.
++ (int) testProperty: (MyClass*) p {
+  int x= 0;
+  [p setValue:0];
+  return 5/[p value]; // expected-warning {{Division by zero}}  
+}
+
 @end
 
 // The class is prvate and is not subclassed.
@@ -100,3 +155,27 @@ int testCallToPublicAPICat(PublicSubClass *p) {
     return 5/m; // expected-warning {{Division by zero}}
   return 5/[p getZeroPublic];// expected-warning {{Division by zero}}  
 }
+
+// Test public property - properties should always be inlined, regardless 
+// weither they are "public" or private. 
+int testPublicProperty(PublicClass *p) {
+  int x = 0;
+  [p setValue3:0];
+  if ([p value3] != 0)
+    return 5/x; // expected-warning {{Division by zero}} // TODO: no warning, we should always inline the property.
+  return 5/[p value3];// expected-warning {{Division by zero}}
+}
+
+int testExtension(PublicClass *p) {
+  int x = 0;
+  [p setValue2:0];
+  if ([p value2] != 0)
+    return 5/x; // expected-warning {{Division by zero}} // TODO: no warning, we should always inline the property.
+  return 5/[p value2]; // expected-warning {{Division by zero}}
+}
+
+// TODO: we do not handle synthesized properties yet.
+int testPropertySynthesized(PublicClass *p) {
+  [p setValue1:0];
+  return 5/[p value1];  
+}
index 715b89eff8c4635054945bbb671a3f8a04f7897b..bb0da280c8ef2b2ca5d98beccfc3d875deb8478d 100644 (file)
@@ -19,8 +19,18 @@ typedef struct objc_object {
 -(id)retain;
 @end
 
-@interface PublicClass : NSObject
+@interface PublicClass : NSObject {
+  int value3;
+}
 - (int)getZeroPublic;
+
+- (int) value2;
+
+@property (readonly) int value1;
+
+@property int value3;
+- (int)value3;
+- (void)setValue3:(int)newValue;
 @end
 
 @interface PublicSubClass : PublicClass