[cfe-commits] r161683 - in /cfe/trunk/test/Analysis/inlining: DynDispatchBifurcate.m InlineObjCInstanceMethod.h
Jordan Rose
jordan_rose at apple.com
Mon Aug 13 18:20:20 PDT 2012
These test cases are a little funny. The only reason we say we can "always inline properties no matter where they're declared" is because they are assumed to have certain semantics. Methods that are merely named like property accessors aren't necessarily promising to follow that contract. In particular, 'value2' isn't really a property, even though you can access it with dot syntax.
The only time we can be 100% sure that we can "inline" a property is if the property is declared atomic, which means we /know/ it's synthesized. Of course, that's exactly the most troublesome case (since we don't know /how/ it's synthesized). We may eventually want an ObjCPropertyRegion that behaves like an ObjCIvarRegion for properties whose definition we can't see, since the whole reason for this rule is (a) to be able to round-trip properties, and (b) to possibly invalidate less than "everything" when accessing them.
On Aug 10, 2012, at 11:56 AM, Anna Zaks <ganna at apple.com> wrote:
> Author: zaks
> Date: Fri Aug 10 13:56:01 2012
> New Revision: 161683
>
> URL: http://llvm.org/viewvc/llvm-project?rev=161683&view=rev
> Log:
> [analyzer] ObjC Inlining: add tests for ivars and properties.
>
> 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.
>
> Modified:
> cfe/trunk/test/Analysis/inlining/DynDispatchBifurcate.m
> cfe/trunk/test/Analysis/inlining/InlineObjCInstanceMethod.h
>
> Modified: cfe/trunk/test/Analysis/inlining/DynDispatchBifurcate.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/inlining/DynDispatchBifurcate.m?rev=161683&r1=161682&r2=161683&view=diff
> ==============================================================================
> --- cfe/trunk/test/Analysis/inlining/DynDispatchBifurcate.m (original)
> +++ cfe/trunk/test/Analysis/inlining/DynDispatchBifurcate.m Fri Aug 10 13:56:01 2012
> @@ -11,10 +11,35 @@
> }
> @end
>
> + at interface PublicClass () {
> + int value2;
> +}
> + at property (readwrite) int value1;
> +- (void)setValue2:(int)newValue2;
> + at end
> +
> @implementation PublicClass
> +
> - (int)getZeroPublic {
> return 0;
> }
> +
> + at 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
> @@ -37,8 +62,11 @@
> @end
>
>
> - at interface MyClass : MyParent
> + at interface MyClass : MyParent {
> + int value;
> +}
> - (int)getZero;
> + at property int value;
> @end
>
> // Since class is private, we assume that it cannot be subclassed.
> @@ -66,6 +94,33 @@
> - (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 @@
> 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];
> +}
>
> Modified: cfe/trunk/test/Analysis/inlining/InlineObjCInstanceMethod.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/inlining/InlineObjCInstanceMethod.h?rev=161683&r1=161682&r2=161683&view=diff
> ==============================================================================
> --- cfe/trunk/test/Analysis/inlining/InlineObjCInstanceMethod.h (original)
> +++ cfe/trunk/test/Analysis/inlining/InlineObjCInstanceMethod.h Fri Aug 10 13:56:01 2012
> @@ -19,8 +19,18 @@
> -(id)retain;
> @end
>
> - at interface PublicClass : NSObject
> + at interface PublicClass : NSObject {
> + int value3;
> +}
> - (int)getZeroPublic;
> +
> +- (int) value2;
> +
> + at property (readonly) int value1;
> +
> + at property int value3;
> +- (int)value3;
> +- (void)setValue3:(int)newValue;
> @end
>
> @interface PublicSubClass : PublicClass
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list