aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/objc.dg/property
diff options
context:
space:
mode:
authorNicola Pero <nicola.pero@meta-innovation.com>2010-11-15 23:12:49 +0000
committerNicola Pero <nicola@gcc.gnu.org>2010-11-15 23:12:49 +0000
commitb6cfe8acc51bf65a1962afbde311cb185debcaf8 (patch)
tree116650c2d71cbf74dc4d68bcf57d5135b736a64b /gcc/testsuite/objc.dg/property
parent567b99c86ed9aa49d20979160613d735555e81f4 (diff)
downloadgcc-b6cfe8acc51bf65a1962afbde311cb185debcaf8.zip
gcc-b6cfe8acc51bf65a1962afbde311cb185debcaf8.tar.gz
gcc-b6cfe8acc51bf65a1962afbde311cb185debcaf8.tar.bz2
In gcc/objc/: 2010-11-15 Nicola Pero <nicola.pero@meta-innovation.com>
In gcc/objc/: 2010-11-15 Nicola Pero <nicola.pero@meta-innovation.com> * objc-act.c (objc_build_setter_call): New. (objc_maybe_build_modify_expr): Rewritten to build a compound statement. (objc_build_incr_expr_for_property_ref): Updated calls to objc_maybe_build_modify_expr to call objc_build_setter_call instead. Use build_modify_expr () instead of build2 (MODIFY_EXPR, ...). Use convert () instead of build1 (NOP_EXPR, ...). Use TREE_NO_WARNING on the final compound statement to silence C++ warnings. In gcc/testsuite/: 2010-11-15 Nicola Pero <nicola.pero@meta-innovation.com> * objc.dg/property/dotsyntax-18.m: New. * objc.dg/property/dotsyntax-19.m: New. * objc.dg/property/dotsyntax-20.m: New. * obj-c++.dg/property/dotsyntax-18.mm: New. * obj-c++.dg/property/dotsyntax-19.mm: New. * obj-c++.dg/property/dotsyntax-20.mm: New. * objc.dg/property/dotsyntax-4.m: Removed some unused variables and code. * objc.dg/property/dotsyntax-6.m: Same change. * objc.dg/property/dotsyntax-16.m: Same change. * objc.dg/property/dotsyntax-17.m: Same change. * obj-c++.dg/property/dotsyntax-4.mm: Same change. * obj-c++.dg/property/dotsyntax-6.mm: Same change. * obj-c++.dg/property/dotsyntax-16.mm: Same change. * obj-c++.dg/property/dotsyntax-17.mm: Same change. * objc.dg/property/at-property-22.m: Added missing casts. * obj-c++.dg/property/at-property-22.mm: Same change. From-SVN: r166779
Diffstat (limited to 'gcc/testsuite/objc.dg/property')
-rw-r--r--gcc/testsuite/objc.dg/property/at-property-22.m14
-rw-r--r--gcc/testsuite/objc.dg/property/dotsyntax-16.m1
-rw-r--r--gcc/testsuite/objc.dg/property/dotsyntax-17.m1
-rw-r--r--gcc/testsuite/objc.dg/property/dotsyntax-18.m90
-rw-r--r--gcc/testsuite/objc.dg/property/dotsyntax-19.m113
-rw-r--r--gcc/testsuite/objc.dg/property/dotsyntax-20.m67
-rw-r--r--gcc/testsuite/objc.dg/property/dotsyntax-4.m25
-rw-r--r--gcc/testsuite/objc.dg/property/dotsyntax-6.m1
8 files changed, 277 insertions, 35 deletions
diff --git a/gcc/testsuite/objc.dg/property/at-property-22.m b/gcc/testsuite/objc.dg/property/at-property-22.m
index af7f3bc..03b3d0b 100644
--- a/gcc/testsuite/objc.dg/property/at-property-22.m
+++ b/gcc/testsuite/objc.dg/property/at-property-22.m
@@ -128,31 +128,31 @@ int main (void)
if (object.penum != Black)
abort ();
- object.pcharp = 0;
+ object.pcharp = (char *)0;
if (object.pcharp != 0)
abort ();
- object.pshortp = 0;
+ object.pshortp = (short *)0;
if (object.pshortp != 0)
abort ();
- object.pintp = 0;
+ object.pintp = (int *)0;
if (object.pintp != 0)
abort ();
- object.plongp = 0;
+ object.plongp = (long *)0;
if (object.plongp != 0)
abort ();
- object.pfloatp = 0;
+ object.pfloatp = (float *)0;
if (object.pfloatp != 0)
abort ();
- object.pdoublep = 0;
+ object.pdoublep = (double *)0;
if (object.pdoublep != 0)
abort ();
- object.penump = 0;
+ object.penump = (enum colour *)0;
if (object.penump != 0)
abort ();
diff --git a/gcc/testsuite/objc.dg/property/dotsyntax-16.m b/gcc/testsuite/objc.dg/property/dotsyntax-16.m
index e0ae3f6..893db69 100644
--- a/gcc/testsuite/objc.dg/property/dotsyntax-16.m
+++ b/gcc/testsuite/objc.dg/property/dotsyntax-16.m
@@ -37,7 +37,6 @@
int main (void)
{
MyRootClass *object = [[MyRootClass alloc] init];
- int i;
object.count = 10;
if (object.count != 10)
diff --git a/gcc/testsuite/objc.dg/property/dotsyntax-17.m b/gcc/testsuite/objc.dg/property/dotsyntax-17.m
index f3942fc..c28e11f 100644
--- a/gcc/testsuite/objc.dg/property/dotsyntax-17.m
+++ b/gcc/testsuite/objc.dg/property/dotsyntax-17.m
@@ -34,7 +34,6 @@
int main (void)
{
MyRootClass *object = [[MyRootClass alloc] init];
- int i;
object.count = 10; /* { dg-error "readonly property can not be set" } */
if (object.count != 10) /* Ok */
diff --git a/gcc/testsuite/objc.dg/property/dotsyntax-18.m b/gcc/testsuite/objc.dg/property/dotsyntax-18.m
new file mode 100644
index 0000000..5697d31
--- /dev/null
+++ b/gcc/testsuite/objc.dg/property/dotsyntax-18.m
@@ -0,0 +1,90 @@
+/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010. */
+/* { dg-do run } */
+/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
+
+/* Test dot-syntax with tricky assignments. */
+
+#include <stdlib.h>
+#include <objc/objc.h>
+#include <objc/runtime.h>
+
+@interface MyRootClass
+{
+ Class isa;
+ int a;
+}
++ (id) initialize;
++ (id) alloc;
+- (id) init;
+- (int) count;
+- (void) setCount: (int)count;
+- (int) somethingToExecuteOnlyOnce;
+@end
+
+@implementation MyRootClass
++ (id) initialize { return self; }
++ (id) alloc { return class_createInstance (self, 0); }
+- (id) init { return self; }
+- (int) count
+{
+ return a;
+}
+- (void) setCount: (int)count
+{
+ a = count;
+}
+- (int) somethingToExecuteOnlyOnce
+{
+ a++;
+ return 10;
+}
+@end
+
+int main (void)
+{
+ MyRootClass *object1 = [[MyRootClass alloc] init];
+ MyRootClass *object2 = [[MyRootClass alloc] init];
+ MyRootClass *object3 = [[MyRootClass alloc] init];
+ int i;
+
+ object1.count = 10;
+ if (object1.count != 10)
+ abort ();
+
+ object2.count = 10;
+ if (object2.count != 10)
+ abort ();
+
+ /* Test multiple assignments to a constant. */
+ object1.count = object2.count = 20;
+
+ if (object1.count != 20 || object2.count != 20)
+ abort ();
+
+ i = object1.count = 30;
+
+ if (i != 30 || object1.count != 30)
+ abort ();
+
+ i = object2.count = 30;
+
+ if (i != 30 || object2.count != 30)
+ abort ();
+
+ /* Test a simple assignment to something with a side-effect; the
+ 'rhs' should be evaluated only once. */
+ object1.count = ([object2 somethingToExecuteOnlyOnce] > 0 ? 30 : 45);
+
+ if (object1.count != 30 || object2.count != 31)
+ abort ();
+
+ /* Test multiple assignments with side effects. */
+ object3.count = object1.count = ([object2 somethingToExecuteOnlyOnce] > 0 ? 30 : 45);
+
+ if (object1.count != 30 || object2.count != 32 || object3.count != 30)
+ abort ();
+
+ return 0;
+}
+
+
diff --git a/gcc/testsuite/objc.dg/property/dotsyntax-19.m b/gcc/testsuite/objc.dg/property/dotsyntax-19.m
new file mode 100644
index 0000000..df4867b
--- /dev/null
+++ b/gcc/testsuite/objc.dg/property/dotsyntax-19.m
@@ -0,0 +1,113 @@
+/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010. */
+/* { dg-do run } */
+/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
+
+/* Test dot-syntax with more tricky assignments. */
+
+#include <stdlib.h>
+#include <objc/objc.h>
+#include <objc/runtime.h>
+
+@interface MyRootClass
+{
+ Class isa;
+ id a;
+ id b;
+ int p1;
+ float p2;
+}
++ (id) initialize;
++ (id) alloc;
+- (id) init;
+
+@property (assign) id object1;
+@property (assign) id object2;
+- (id) test;
+- (id) myself;
+- (id) nilObject;
+
+@property int p1;
+@property float p2;
+@end
+
+@implementation MyRootClass
++ (id) initialize { return self; }
++ (id) alloc { return class_createInstance (self, 0); }
+- (id) init { return self; }
+@synthesize object1 = a;
+@synthesize object2 = b;
+- (id) test
+{
+ /* Test multiple assignments with 'self'. */
+ self.object1 = self.object2 = self;
+
+ if (self.object1 != self || self.object2 != self)
+ abort ();
+
+ /* Test multiple assignments with a conditional and method calls. */
+ self.object1 = self.object2 = (self ? [self myself] : [self nilObject]);
+
+ if (self.object1 != self || self.object2 != self)
+ abort ();
+
+ self.object1 = self.object2 = (self ? [self nilObject] : [self myself]);
+
+ if (self.object1 != nil || self.object2 != nil)
+ abort ();
+
+ return self.object1;
+}
+- (id) myself
+{
+ return self;
+}
+- (id) nilObject
+{
+ return nil;
+}
+
+@synthesize p1;
+@synthesize p2;
+@end
+
+int main (void)
+{
+ MyRootClass *object = [[MyRootClass alloc] init];
+ MyRootClass *object1 = [[MyRootClass alloc] init];
+
+ [object test];
+
+ /* Now, test multiple assignments with different types. Use
+ int/float as they seem to happily crash the compiler in gimplify
+ if proper conversions are not being generated by the
+ frontend. ;-) */
+ object.p1 = object.p2 = 12;
+
+ if (object.p1 != 12 || object.p2 != 12)
+ abort ();
+
+ object.p1 = object.p2 = 2.7;
+
+ if (object.p1 != 2)
+ abort ();
+
+ /* Just try a different loop, mixing in a few different standard C
+ constructs to cover a few other cases. */
+ object.p1 = 10;
+ object1.p1 = 0;
+ while (object.p1)
+ {
+ object1.p1 += ((object.p2 = 4.56) ? 0 : object.p1);
+ object.p1--;
+ }
+
+ if (object.p1 != 0 || object1.p1 != 0)
+ abort ();
+
+ if ((object.p1 = 0))
+ abort ();
+
+ return 0;
+}
+
+
diff --git a/gcc/testsuite/objc.dg/property/dotsyntax-20.m b/gcc/testsuite/objc.dg/property/dotsyntax-20.m
new file mode 100644
index 0000000..f1dd48e
--- /dev/null
+++ b/gcc/testsuite/objc.dg/property/dotsyntax-20.m
@@ -0,0 +1,67 @@
+/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010. */
+/* { dg-do compile } */
+/* { dg-options "-Wall" } */
+
+/* Test warnings with the dot-syntax. */
+
+#include <stdlib.h>
+#include <objc/objc.h>
+#include <objc/runtime.h>
+
+@interface MyRootClass
+{
+ Class isa;
+ id a;
+ id b;
+ int p1;
+ int p2;
+}
++ (id) initialize;
++ (id) alloc;
+- (id) init;
+
+@property int p1;
+@property int p2;
+@end
+
+@implementation MyRootClass
++ (id) initialize { return self; }
++ (id) alloc { return class_createInstance (self, 0); }
+- (id) init { return self; }
+@synthesize p1;
+@synthesize p2;
+@end
+
+int main (void)
+{
+ MyRootClass *object = [[MyRootClass alloc] init];
+
+ /* First, test that the artificial code generated by dot-syntax does
+ not generate unexpected warnings. */
+
+ /* All of the following should generate no warnings. */
+ object.p1 = 0;
+ object.p2 = 0;
+ object.p1 = object.p2 = 0;
+ if (object.p1 > 0)
+ object.p2 = 0;
+
+ object.p1++;
+ ++object.p1;
+ object.p1--;
+ --object.p1;
+
+ while (object.p1)
+ object.p1--;
+
+ /* Now test some warnings. */
+ object.p1; /* { dg-warning "value computed is not used" } */
+
+ /* TODO: It would be good to get the following to warn. */
+ if (object.p1 = 0) /* dg-warning "suggest parentheses around assignment used as truth value" */
+ abort ();
+
+ return 0;
+}
+
+
diff --git a/gcc/testsuite/objc.dg/property/dotsyntax-4.m b/gcc/testsuite/objc.dg/property/dotsyntax-4.m
index d890f3b..2db067f 100644
--- a/gcc/testsuite/objc.dg/property/dotsyntax-4.m
+++ b/gcc/testsuite/objc.dg/property/dotsyntax-4.m
@@ -9,9 +9,6 @@
#include <objc/objc.h>
#include <objc/runtime.h>
-static int a;
-static id b;
-
@interface MyRootClass
{
Class isa;
@@ -19,38 +16,16 @@ static id b;
+ (id) initialize;
+ (id) alloc;
- (id) init;
-+ (int) count;
-+ (void) setCount: (int)value;
-+ (id) next;
-+ (void) setNext: (id)value;
@end
@implementation MyRootClass
+ (id) initialize { return self; }
+ (id) alloc { return class_createInstance (self, 0); }
- (id) init { return self; }
-+ (int) count
-{
- return a;
-}
-+ (void) setCount: (int)value
-{
- a = value;
-}
-+ (id) next
-{
- return b;
-}
-+ (void) setNext: (id)value
-{
- b = value;
-}
@end
int main (void)
{
- MyRootClass *object = [[MyRootClass alloc] init];
-
MyRootClass.invalid = 40; /* { dg-error "could not find setter.getter" } */
if (MyRootClass.invalid != 40) /* { dg-error "could not find setter.getter" } */
abort ();
diff --git a/gcc/testsuite/objc.dg/property/dotsyntax-6.m b/gcc/testsuite/objc.dg/property/dotsyntax-6.m
index cc8c567c..7ecd34e 100644
--- a/gcc/testsuite/objc.dg/property/dotsyntax-6.m
+++ b/gcc/testsuite/objc.dg/property/dotsyntax-6.m
@@ -10,7 +10,6 @@
@class MyRootClass;
-static int c;
static MyRootClass *shared_root = nil;
@interface MyRootClass