diff mbox

ObjC/ObjC++: Fix property encoding on Apple

Message ID 3727086D-6A36-4CA0-B0E3-6376EBDF16F0@meta-innovation.com
State New
Headers show

Commit Message

Nicola Pero Feb. 25, 2011, 9:16 a.m. UTC
>> PS: I tested on Apple m32.  I don't have an Apple m64.  I'd be  
>> grateful
>> if someone could try out the
>> patch on there before I commit to confirm that it all looks good  
>> there.
>> Thank! :-)
>
> Nicola,
>   Can you repost the patch as an attachment? Your emailer seems to
> have reformatted the patch so that it is considered as malformed by
> patch and can't be applied against gcc trunk.

No problem.  Patch (against trunk revision 170489) is in attach.   
Thanks for your help! :-)

Thanks

Comments

Mike Stump Feb. 25, 2011, 9:56 a.m. UTC | #1
On Feb 25, 2011, at 1:16 AM, Nicola Pero <nicola.pero@meta-innovation.com> wrote:
> No problem.  Patch (against trunk revision 170489) is in attach.

Ok.
>
Jack Howarth Feb. 26, 2011, 1:59 a.m. UTC | #2
On Fri, Feb 25, 2011 at 09:16:08AM +0000, Nicola Pero wrote:
>
>>> PS: I tested on Apple m32.  I don't have an Apple m64.  I'd be  
>>> grateful
>>> if someone could try out the
>>> patch on there before I commit to confirm that it all looks good  
>>> there.
>>> Thank! :-)
>>
>> Nicola,
>>   Can you repost the patch as an attachment? Your emailer seems to
>> have reformatted the patch so that it is considered as malformed by
>> patch and can't be applied against gcc trunk.
>
> No problem.  Patch (against trunk revision 170489) is in attach.  Thanks 
> for your help! :-)
>
> Thanks

Nicola,
   The results for x86_64-apple-darwin10 are....

Native configuration is x86_64-apple-darwin10.7.0

		=== objc tests ===


Running target unix/-m32

		=== objc Summary for unix/-m32 ===

# of expected passes		5955
# of expected failures		6
# of unsupported tests		86

Running target unix/-m64
FAIL: objc.dg/property/property-encoding-1.m -fnext-runtime execution test

		=== objc Summary for unix/-m64 ===

# of expected passes		5876
# of unexpected failures	1
# of expected failures		24
# of unsupported tests		102

		=== objc Summary ===

# of expected passes		11831
# of unexpected failures	1
# of expected failures		30
# of unsupported tests		188
/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/gcc/xgcc  version 4.6.0 20110225 (experimental) (GCC) 


Compiler version: 4.6.0 20110225 (experimental) (GCC) objc 
Platform: x86_64-apple-darwin10.7.0
configure flags: --prefix=/sw --prefix=/sw/lib/gcc4.6 --mandir=/sw/share/man --infodir=/sw/lib/gcc4.6/info --with-build-config=bootstrap-lto --enable-stage1-languages=c,lto --enable-languages=c,c++,fortran,lto,objc,obj-c++,java --enable-build-with-cxx --with-gmp=/sw --with-libiconv-prefix=/sw --with-ppl=/sw --with-cloog=/sw --with-mpc=/sw --with-system-zlib --x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib --program-suffix=-fsf-4.6 --enable-checking=yes --enable-cloog-backend=isl

This failure at -m64 appears as...

Executing on host: /sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/gcc/xgcc -B/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/gcc/ /sw/src/fink.build/gcc46-4.6.0-1000/gcc-4.6-20110225/gcc/testsuite/objc.dg/property/property-encoding-1.m  -fnext-runtime   -B/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/x86_64-apple-darwin10.7.0/./libobjc/.libs   -L/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/x86_64-apple-darwin10.7.0/./libobjc/.libs   -lobjc -lm   -m64 -o ./property-encoding-1.exe    (timeout = 300)
PASS: objc.dg/property/property-encoding-1.m -fnext-runtime (test for excess errors)
Setting LD_LIBRARY_PATH to .::/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/gcc:/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/x86_64-apple-darwin10.7.0/./libobjc/.libs:.::/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/gcc:/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/x86_64-apple-darwin10.7.0/./libobjc/.libs
Error - property_getAttributes ("long_property") returns "Tq,Vlong_property"
FAIL: objc.dg/property/property-encoding-1.m -fnext-runtime execution test

>

> Index: gcc/objc/ChangeLog
> ===================================================================
> --- gcc/objc/ChangeLog	(revision 170489)
> +++ gcc/objc/ChangeLog	(working copy)
> @@ -1,3 +1,7 @@
> +2011-02-25  Nicola Pero  <nicola.pero@meta-innovation.com>
> +
> +	* objc-act.c (objc_v2_encode_prop_attr): Rewritten.
> +	
>  2011-02-23  Nicola Pero  <nicola.pero@meta-innovation.com>
>  
>  	* objc-act.c (build_private_template): Do not copy the
> @@ -16,7 +20,8 @@
>  
>  2011-02-21  Mike Stump  <mikestump@comcast.net>
>  
> -	* Make-lang.in (check_objc_parallelize): Refine for 4 processor machines.
> +	* Make-lang.in (check_objc_parallelize): Refine for 4 processor
> +	machines.
>  
>  2011-02-20  Nicola Pero  <nicola.pero@meta-innovation.com>
>  
> Index: gcc/objc/objc-act.c
> ===================================================================
> --- gcc/objc/objc-act.c	(revision 170489)
> +++ gcc/objc/objc-act.c	(working copy)
> @@ -10495,47 +10495,79 @@
>       kPropertyGetter = 'G',
>       kPropertySetter = 'S',
>       kPropertyInstanceVariable = 'V',
> -     kPropertyType = 't',
> +     kPropertyType = 'T',
>       kPropertyWeak = 'W',
> -     kPropertyStrong = 'S',
> +     kPropertyStrong = 'P',
>       kPropertyNonAtomic = 'N'
> -   };
> -
> -   FIXME: Update the implementation to match.  */
> +   };  */
>  tree
>  objc_v2_encode_prop_attr (tree property)
>  {
>    const char *string;
>    tree type = TREE_TYPE (property);
> -  obstack_1grow (&util_obstack, 't');
> +
> +  obstack_1grow (&util_obstack, 'T');
>    encode_type (type, obstack_object_size (&util_obstack),
>  	       OBJC_ENCODE_INLINE_DEFS);
> +
>    if (PROPERTY_READONLY (property))
> -    obstack_grow (&util_obstack, ",r", 2);
> +    obstack_grow (&util_obstack, ",R", 2);
>  
> -  if (PROPERTY_ASSIGN_SEMANTICS (property) == OBJC_PROPERTY_COPY)
> -    obstack_grow (&util_obstack, ",c", 2);
> +  switch (PROPERTY_ASSIGN_SEMANTICS (property))
> +    {
> +    case OBJC_PROPERTY_COPY:
> +      obstack_grow (&util_obstack, ",C", 2);
> +      break;
> +    case OBJC_PROPERTY_RETAIN:
> +      obstack_grow (&util_obstack, ",&", 2);
> +      break;
> +    case OBJC_PROPERTY_ASSIGN:
> +    default:
> +      break;
> +    }
>  
> -  if (PROPERTY_GETTER_NAME (property))
> +  if (PROPERTY_DYNAMIC (property))
> +    obstack_grow (&util_obstack, ",D", 2);    
> +
> +  if (PROPERTY_NONATOMIC (property))
> +    obstack_grow (&util_obstack, ",N", 2);
> +
> +  /* Here we want to encode the getter name, but only if it's not the
> +     standard one.  */
> +  if (PROPERTY_GETTER_NAME (property) != PROPERTY_NAME (property))
>      {
> -      obstack_grow (&util_obstack, ",g", 2);
> +      obstack_grow (&util_obstack, ",G", 2);
>        string = IDENTIFIER_POINTER (PROPERTY_GETTER_NAME (property));
>        obstack_grow (&util_obstack, string, strlen (string));
>      }
> -  if (PROPERTY_SETTER_NAME (property))
> +
> +  if (!PROPERTY_READONLY (property))
>      {
> -      obstack_grow (&util_obstack, ",s", 2);
> -      string = IDENTIFIER_POINTER (PROPERTY_SETTER_NAME (property));
> -      obstack_grow (&util_obstack, string, strlen (string));
> +      /* Here we want to encode the setter name, but only if it's not
> +	 the standard one.  */
> +      tree standard_setter = get_identifier (objc_build_property_setter_name (PROPERTY_NAME (property)));
> +      if (PROPERTY_SETTER_NAME (property) != standard_setter)
> +	{
> +	  obstack_grow (&util_obstack, ",S", 2);
> +	  string = IDENTIFIER_POINTER (PROPERTY_SETTER_NAME (property));
> +	  obstack_grow (&util_obstack, string, strlen (string));
> +	}
>      }
> -  if (PROPERTY_IVAR_NAME (property))
> +
> +  /* TODO: Encode strong ('P'), weak ('W') for garbage collection.  */
> +
> +  if (!PROPERTY_DYNAMIC (property))
>      {
> -      obstack_grow (&util_obstack, ",i", 2);
> -      string = IDENTIFIER_POINTER (PROPERTY_IVAR_NAME (property));
> +      obstack_grow (&util_obstack, ",V", 2);
> +      if (PROPERTY_IVAR_NAME (property))
> +	string = IDENTIFIER_POINTER (PROPERTY_IVAR_NAME (property));
> +      else
> +	string = IDENTIFIER_POINTER (PROPERTY_NAME (property));
>        obstack_grow (&util_obstack, string, strlen (string));
>      }
> -    
> -  obstack_1grow (&util_obstack, 0);    /* null terminate string */
> +
> +  /* NULL-terminate string.  */
> +  obstack_1grow (&util_obstack, 0);
>    string = XOBFINISH (&util_obstack, char *);
>    obstack_free (&util_obstack, util_firstobj);
>    return get_identifier (string);
> Index: gcc/testsuite/ChangeLog
> ===================================================================
> --- gcc/testsuite/ChangeLog	(revision 170489)
> +++ gcc/testsuite/ChangeLog	(working copy)
> @@ -1,3 +1,11 @@
> +2011-02-25  Nicola Pero  <nicola.pero@meta-innovation.com>
> +
> +	* objc.dg/gnu-api-2-property.m: Added tests for property_getName()
> +	and property_getAttributes() if __OBJC2__.
> +	* obj-c++.dg/gnu-api-2-property.mm: Likewise.
> +	* objc.dg/property/property-encoding-1.m: New.
> +	* obj-c++.dg/property/property-encoding-1.mm: New.
> +
>  2011-02-24  Jason Merrill  <jason@redhat.com>
>  
>  	* g++.dg/parse/constant1.C: Specify C++98 mode.
> Index: gcc/testsuite/objc.dg/property/property-encoding-1.m
> ===================================================================
> --- gcc/testsuite/objc.dg/property/property-encoding-1.m	(revision 0)
> +++ gcc/testsuite/objc.dg/property/property-encoding-1.m	(revision 0)
> @@ -0,0 +1,160 @@
> +/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, February 2011.  */
> +/* Test encoding properties.  */
> +/* { dg-do run } */
> +/* { dg-skip-if "No API#2 pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */
> +
> +#include <objc/runtime.h>
> +#include <stdlib.h>
> +#include <stdio.h>
> +#include <string.h>
> +
> +@interface MyRootClass
> +{ Class isa; }
> ++ alloc;
> +- init;
> ++ initialize;
> +@end
> +
> +@implementation MyRootClass
> ++ alloc { return class_createInstance (self, 0); }
> +- init  { return self; }
> ++ initialize { return self; }
> +@end
> +
> +@interface MySubClass : MyRootClass
> +{
> +  char char_property;
> +  short short_property;
> +  int int_property;
> +  long long_property;
> +  float float_property;
> +  double double_property;
> +  int *int_pointer_property;
> +
> +  id propertyA;
> +  id propertyB;
> +  id propertyC;
> +  id propertyD;
> +  int propertyE;
> +  id propertyF;
> +
> +  id other_variable;
> +}
> +@property char char_property;
> +@property short short_property;
> +@property int int_property;
> +@property long long_property;
> +@property float float_property;
> +@property double double_property;
> +@property int *int_pointer_property;
> +
> +@property (assign, getter=getP, setter=setP:) id propertyA;
> +@property (assign) id propertyB;
> +@property (copy) id propertyC;
> +@property (retain) id propertyD;
> +@property (nonatomic) int propertyE;
> +@property (nonatomic, readonly, copy) id propertyF;
> +
> +@property (assign) id propertyG;
> +@property (assign, readonly, getter=X) id propertyH;
> +@end
> +
> +@implementation MySubClass
> +@synthesize char_property;
> +@synthesize short_property;
> +@synthesize int_property;
> +@synthesize long_property;
> +@synthesize float_property;
> +@synthesize double_property;
> +@synthesize int_pointer_property;
> +
> +@synthesize propertyA;
> +@synthesize propertyB;
> +@synthesize propertyC;
> +@synthesize propertyD;
> +@synthesize propertyE;
> +@synthesize propertyF;
> +
> +@synthesize propertyG = other_variable;
> +@dynamic propertyH;
> +@end
> +
> +#ifdef __OBJC2__
> +void error (objc_property_t p)
> +{
> +  printf ("Error - property_getAttributes (\"%s\") returns \"%s\"\n",
> +	  property_getName (p),
> +	  property_getAttributes (p));
> +  abort ();
> +}
> +#endif
> +
> +int main(int argc, void **args)
> +{
> +#ifdef __OBJC2__
> +  Class c = objc_getClass ("MySubClass");
> +  objc_property_t p;
> +
> +  p = class_getProperty (c, "char_property");
> +  if (strcmp ("Tc,Vchar_property", property_getAttributes (p)) != 0)
> +    error (p);
> +
> +  p = class_getProperty (c, "short_property");
> +  if (strcmp ("Ts,Vshort_property", property_getAttributes (p)) != 0)
> +    error (p);
> +
> +  p = class_getProperty (c, "int_property");
> +  if (strcmp ("Ti,Vint_property", property_getAttributes (p)) != 0)
> +    error (p);
> +
> +  p = class_getProperty (c, "long_property");
> +  if (strcmp ("Tl,Vlong_property", property_getAttributes (p)) != 0)
> +    error (p);
> +
> +  p = class_getProperty (c, "float_property");
> +  if (strcmp ("Tf,Vfloat_property", property_getAttributes (p)) != 0)
> +    error (p);
> +
> +  p = class_getProperty (c, "double_property");
> +  if (strcmp ("Td,Vdouble_property", property_getAttributes (p)) != 0)
> +    error (p);
> +
> +  p = class_getProperty (c, "int_pointer_property");
> +  if (strcmp ("T^i,Vint_pointer_property", property_getAttributes (p)) != 0)
> +    error (p);
> +
> +  p = class_getProperty (c, "propertyA");
> +  if (strcmp ("T@,GgetP,SsetP:,VpropertyA", property_getAttributes (p)) != 0)
> +    error (p);
> +
> +  p = class_getProperty (c, "propertyB");
> +  if (strcmp ("T@,VpropertyB", property_getAttributes (p)) != 0)
> +    error (p);
> +
> +  p = class_getProperty (c, "propertyC");
> +  if (strcmp ("T@,C,VpropertyC", property_getAttributes (p)) != 0)
> +    error (p);
> +
> +  p = class_getProperty (c, "propertyD");
> +  if (strcmp ("T@,&,VpropertyD", property_getAttributes (p)) != 0)
> +    error (p);
> +
> +  p = class_getProperty (c, "propertyE");
> +  if (strcmp ("Ti,N,VpropertyE", property_getAttributes (p)) != 0)
> +    error (p);
> +
> +  p = class_getProperty (c, "propertyF");
> +  if (strcmp ("T@,R,C,N,VpropertyF", property_getAttributes (p)) != 0)
> +    error (p);
> +
> +  p = class_getProperty (c, "propertyG");
> +  if (strcmp ("T@,Vother_variable", property_getAttributes (p)) != 0)
> +    error (p);
> +
> +  p = class_getProperty (c, "propertyH");
> +  if (strcmp ("T@,R,D,GX", property_getAttributes (p)) != 0)
> +    error (p);
> +#endif
> +
> +  return 0;
> +}
> Index: gcc/testsuite/objc.dg/gnu-api-2-property.m
> ===================================================================
> --- gcc/testsuite/objc.dg/gnu-api-2-property.m	(revision 170489)
> +++ gcc/testsuite/objc.dg/gnu-api-2-property.m	(working copy)
> @@ -25,23 +25,18 @@
>  + initialize { return self; }
>  @end
>  
> -@protocol MyProtocol
> -- (id) variable;
> +@interface MySubClass : MyRootClass
> +{
> +  id propertyA;
> +  id propertyB;
> +}
> +@property (assign, getter=getP, setter=setP:) id propertyA;
> +@property (assign, nonatomic) id propertyB;
>  @end
>  
> -@protocol MySecondProtocol
> -- (id) setVariable: (id)value;
> -@end
> -
> -@interface MySubClass : MyRootClass <MyProtocol>
> -{ id variable_ivar; }
> -- (void) setVariable: (id)value;
> -- (id) variable;
> -@end
> -
>  @implementation MySubClass
> -- (void) setVariable: (id)value { variable_ivar = value; }
> -- (id) variable { return variable_ivar; }
> +@synthesize propertyA;
> +@synthesize propertyB;
>  @end
>  
>  
> @@ -49,7 +44,6 @@
>  {
>    /* Functions are tested in alphabetical order.  */
>  
> -  /* TODO: Test new ABI (when available).  */
>    printf ("Testing property_getAttributes () ...\n");
>    {
>      /* The Apple/NeXT runtime seems to crash on the following.  */
> @@ -57,9 +51,26 @@
>      if (property_getAttributes (NULL) != NULL)
>        abort ();
>  #endif
> +
> +    /* The GNU runtime doesn't support looking up properties at
> +       runtime yet.  */
> +#ifdef __OBJC2__
> +    {
> +      objc_property_t property;
> +      
> +      property = class_getProperty (objc_getClass ("MySubClass"), "propertyA");
> +      if (strcmp (property_getAttributes (property),
> +		  "T@,GgetP,SsetP:,VpropertyA") != 0)
> +	abort ();
> +
> +      property = class_getProperty (objc_getClass ("MySubClass"), "propertyB");
> +      if (strcmp (property_getAttributes (property),
> +		  "T@,N,VpropertyB") != 0)
> +	abort ();
> +    }
> +#endif    
>    }
>  
> -  /* TODO: Test new ABI (when available).  */
>    printf ("Testing property_getName () ...\n");
>    {
>      /* The Apple/NeXT runtime seems to crash on the following.  */
> @@ -67,6 +78,22 @@
>      if (property_getName (NULL) != NULL)
>        abort ();
>  #endif
> +
> +    /* The GNU runtime doesn't support looking up properties at
> +       runtime yet.  */
> +#ifdef __OBJC2__
> +    {
> +      objc_property_t property;
> +      
> +      property = class_getProperty (objc_getClass ("MySubClass"), "propertyA");
> +      if (strcmp (property_getName (property), "propertyA") != 0)
> +	abort ();
> +
> +      property = class_getProperty (objc_getClass ("MySubClass"), "propertyB");
> +      if (strcmp (property_getName (property), "propertyB") != 0)
> +	abort ();
> +    }
> +#endif
>    }
>  
>    return 0;
> Index: gcc/testsuite/obj-c++.dg/property/property-encoding-1.mm
> ===================================================================
> --- gcc/testsuite/obj-c++.dg/property/property-encoding-1.mm	(revision 0)
> +++ gcc/testsuite/obj-c++.dg/property/property-encoding-1.mm	(revision 0)
> @@ -0,0 +1,160 @@
> +/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, February 2011.  */
> +/* Test encoding properties.  */
> +/* { dg-do run } */
> +/* { dg-skip-if "No API#2 pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */
> +
> +#include <objc/runtime.h>
> +#include <stdlib.h>
> +#include <stdio.h>
> +#include <string.h>
> +
> +@interface MyRootClass
> +{ Class isa; }
> ++ alloc;
> +- init;
> ++ initialize;
> +@end
> +
> +@implementation MyRootClass
> ++ alloc { return class_createInstance (self, 0); }
> +- init  { return self; }
> ++ initialize { return self; }
> +@end
> +
> +@interface MySubClass : MyRootClass
> +{
> +  char char_property;
> +  short short_property;
> +  int int_property;
> +  long long_property;
> +  float float_property;
> +  double double_property;
> +  int *int_pointer_property;
> +
> +  id propertyA;
> +  id propertyB;
> +  id propertyC;
> +  id propertyD;
> +  int propertyE;
> +  id propertyF;
> +
> +  id other_variable;
> +}
> +@property char char_property;
> +@property short short_property;
> +@property int int_property;
> +@property long long_property;
> +@property float float_property;
> +@property double double_property;
> +@property int *int_pointer_property;
> +
> +@property (assign, getter=getP, setter=setP:) id propertyA;
> +@property (assign) id propertyB;
> +@property (copy) id propertyC;
> +@property (retain) id propertyD;
> +@property (nonatomic) int propertyE;
> +@property (nonatomic, readonly, copy) id propertyF;
> +
> +@property (assign) id propertyG;
> +@property (assign, readonly, getter=X) id propertyH;
> +@end
> +
> +@implementation MySubClass
> +@synthesize char_property;
> +@synthesize short_property;
> +@synthesize int_property;
> +@synthesize long_property;
> +@synthesize float_property;
> +@synthesize double_property;
> +@synthesize int_pointer_property;
> +
> +@synthesize propertyA;
> +@synthesize propertyB;
> +@synthesize propertyC;
> +@synthesize propertyD;
> +@synthesize propertyE;
> +@synthesize propertyF;
> +
> +@synthesize propertyG = other_variable;
> +@dynamic propertyH;
> +@end
> +
> +#ifdef __OBJC2__
> +void error (objc_property_t p)
> +{
> +  printf ("Error - property_getAttributes (\"%s\") returns \"%s\"\n",
> +	  property_getName (p),
> +	  property_getAttributes (p));
> +  abort ();
> +}
> +#endif
> +
> +int main(int argc, char **args)
> +{
> +#ifdef __OBJC2__
> +  Class c = objc_getClass ("MySubClass");
> +  objc_property_t p;
> +
> +  p = class_getProperty (c, "char_property");
> +  if (strcmp ("Tc,Vchar_property", property_getAttributes (p)) != 0)
> +    error (p);
> +
> +  p = class_getProperty (c, "short_property");
> +  if (strcmp ("Ts,Vshort_property", property_getAttributes (p)) != 0)
> +    error (p);
> +
> +  p = class_getProperty (c, "int_property");
> +  if (strcmp ("Ti,Vint_property", property_getAttributes (p)) != 0)
> +    error (p);
> +
> +  p = class_getProperty (c, "long_property");
> +  if (strcmp ("Tl,Vlong_property", property_getAttributes (p)) != 0)
> +    error (p);
> +
> +  p = class_getProperty (c, "float_property");
> +  if (strcmp ("Tf,Vfloat_property", property_getAttributes (p)) != 0)
> +    error (p);
> +
> +  p = class_getProperty (c, "double_property");
> +  if (strcmp ("Td,Vdouble_property", property_getAttributes (p)) != 0)
> +    error (p);
> +
> +  p = class_getProperty (c, "int_pointer_property");
> +  if (strcmp ("T^i,Vint_pointer_property", property_getAttributes (p)) != 0)
> +    error (p);
> +
> +  p = class_getProperty (c, "propertyA");
> +  if (strcmp ("T@,GgetP,SsetP:,VpropertyA", property_getAttributes (p)) != 0)
> +    error (p);
> +
> +  p = class_getProperty (c, "propertyB");
> +  if (strcmp ("T@,VpropertyB", property_getAttributes (p)) != 0)
> +    error (p);
> +
> +  p = class_getProperty (c, "propertyC");
> +  if (strcmp ("T@,C,VpropertyC", property_getAttributes (p)) != 0)
> +    error (p);
> +
> +  p = class_getProperty (c, "propertyD");
> +  if (strcmp ("T@,&,VpropertyD", property_getAttributes (p)) != 0)
> +    error (p);
> +
> +  p = class_getProperty (c, "propertyE");
> +  if (strcmp ("Ti,N,VpropertyE", property_getAttributes (p)) != 0)
> +    error (p);
> +
> +  p = class_getProperty (c, "propertyF");
> +  if (strcmp ("T@,R,C,N,VpropertyF", property_getAttributes (p)) != 0)
> +    error (p);
> +
> +  p = class_getProperty (c, "propertyG");
> +  if (strcmp ("T@,Vother_variable", property_getAttributes (p)) != 0)
> +    error (p);
> +
> +  p = class_getProperty (c, "propertyH");
> +  if (strcmp ("T@,R,D,GX", property_getAttributes (p)) != 0)
> +    error (p);
> +#endif
> +
> +  return 0;
> +}
> Index: gcc/testsuite/obj-c++.dg/gnu-api-2-property.mm
> ===================================================================
> --- gcc/testsuite/obj-c++.dg/gnu-api-2-property.mm	(revision 170489)
> +++ gcc/testsuite/obj-c++.dg/gnu-api-2-property.mm	(working copy)
> @@ -25,23 +25,18 @@
>  + initialize { return self; }
>  @end
>  
> -@protocol MyProtocol
> -- (id) variable;
> +@interface MySubClass : MyRootClass
> +{
> +  id propertyA;
> +  id propertyB;
> +}
> +@property (assign, getter=getP, setter=setP:) id propertyA;
> +@property (assign, nonatomic) id propertyB;
>  @end
>  
> -@protocol MySecondProtocol
> -- (id) setVariable: (id)value;
> -@end
> -
> -@interface MySubClass : MyRootClass <MyProtocol>
> -{ id variable_ivar; }
> -- (void) setVariable: (id)value;
> -- (id) variable;
> -@end
> -
>  @implementation MySubClass
> -- (void) setVariable: (id)value { variable_ivar = value; }
> -- (id) variable { return variable_ivar; }
> +@synthesize propertyA;
> +@synthesize propertyB;
>  @end
>  
>  
> @@ -49,7 +44,6 @@
>  {
>    /* Functions are tested in alphabetical order.  */
>  
> -  /* TODO: Test new ABI (when available).  */
>    std::cout << "Testing property_getAttributes () ...\n";
>    {
>      /* The Apple/NeXT runtime seems to crash on the following.  */
> @@ -57,9 +51,26 @@
>      if (property_getAttributes (NULL) != NULL)
>        abort ();
>  #endif
> +
> +    /* The GNU runtime doesn't support looking up properties at
> +       runtime yet.  */
> +#ifdef __OBJC2__
> +    {
> +      objc_property_t property;
> +      
> +      property = class_getProperty (objc_getClass ("MySubClass"), "propertyA");
> +      if (std::strcmp (property_getAttributes (property),
> +		  "T@,GgetP,SsetP:,VpropertyA") != 0)
> +	abort ();
> +
> +      property = class_getProperty (objc_getClass ("MySubClass"), "propertyB");
> +      if (std::strcmp (property_getAttributes (property),
> +		  "T@,N,VpropertyB") != 0)
> +	abort ();
> +    }
> +#endif    
>    }
>  
> -  /* TODO: Test new ABI (when available).  */
>    std::cout << "Testing property_getName () ...\n";
>    {
>      /* The Apple/NeXT runtime seems to crash on the following.  */
> @@ -68,6 +79,22 @@
>      if (property_getName (NULL) != NULL)
>        abort ();
>  #endif
> +
> +    /* The GNU runtime doesn't support looking up properties at
> +       runtime yet.  */
> +#ifdef __OBJC2__
> +    {
> +      objc_property_t property;
> +      
> +      property = class_getProperty (objc_getClass ("MySubClass"), "propertyA");
> +      if (std::strcmp (property_getName (property), "propertyA") != 0)
> +	abort ();
> +
> +      property = class_getProperty (objc_getClass ("MySubClass"), "propertyB");
> +      if (std::strcmp (property_getName (property), "propertyB") != 0)
> +	abort ();
> +    }
> +#endif
>    }
>  
>    return (0);

>
Nicola Pero Feb. 26, 2011, 11:31 a.m. UTC | #3
Jack,

thanks a lot for your help.  I'm glad I asked, as you spotted a  
problem :-)

> Error - property_getAttributes ("long_property") returns  
> "Tq,Vlong_property"
> FAIL: objc.dg/property/property-encoding-1.m -fnext-runtime  
> execution test

Ah!  That's because @encode(long) is 'q' as opposed to 'l' on that  
architecture.

  In attach, the testcase adjusted to work no matter when the encoding  
of the various
integer types is.  It works for me on 32-bit if I manually force - 
fobjc-abi-version=1.

Can you replace that test with this one and let me know how it  
goes ? :-)

Thanks
Nicola Pero Feb. 26, 2011, 11:41 a.m. UTC | #4
> In attach, the testcase adjusted to work no matter when the encoding  
> of the various
> integer types is.  It works for me on 32-bit if I manually force - 
> fobjc-abi-version=1.
>
> Can you replace that test with this one and let me know how it  
> goes ? :-)

To clarify, there is no problem with the actual objc-act.c code, which  
seems fine (and I committed it).

Even the error message that Jack got on 64-bit shows that the property  
was actually encoded correctly;
it's the testcase that needs to be more sophisticated. ;-)

Thanks
Jack Howarth Feb. 26, 2011, 3:46 p.m. UTC | #5
On Sat, Feb 26, 2011 at 11:31:30AM +0000, Nicola Pero wrote:
> Jack,
>
> thanks a lot for your help.  I'm glad I asked, as you spotted a problem 
> :-)
>
>> Error - property_getAttributes ("long_property") returns  
>> "Tq,Vlong_property"
>> FAIL: objc.dg/property/property-encoding-1.m -fnext-runtime execution 
>> test
>
> Ah!  That's because @encode(long) is 'q' as opposed to 'l' on that  
> architecture.
>
>  In attach, the testcase adjusted to work no matter when the encoding of 
> the various
> integer types is.  It works for me on 32-bit if I manually force - 
> fobjc-abi-version=1.
>
> Can you replace that test with this one and let me know how it goes ? :-)
>
> Thanks
>

Nicola,
   I can confirm that your replacement property-encoding-1.m eliminates the
failures at -m64 on x86_64-apple-darwin10. Thanks for fixing that.
               Jack

>
Jack Howarth March 1, 2011, 1:26 p.m. UTC | #6
On Sat, Feb 26, 2011 at 11:31:30AM +0000, Nicola Pero wrote:
> Jack,
>
> thanks a lot for your help.  I'm glad I asked, as you spotted a problem 
> :-)
>
>> Error - property_getAttributes ("long_property") returns  
>> "Tq,Vlong_property"
>> FAIL: objc.dg/property/property-encoding-1.m -fnext-runtime execution 
>> test
>
> Ah!  That's because @encode(long) is 'q' as opposed to 'l' on that  
> architecture.
>
>  In attach, the testcase adjusted to work no matter when the encoding of 
> the various
> integer types is.  It works for me on 32-bit if I manually force - 
> fobjc-abi-version=1.
>
> Can you replace that test with this one and let me know how it goes ? :-)
>
> Thanks
>

Nicola,
   The file you attached isn't a replacement property-encoding-1.m file.
I manually changed the lines to + to remove those and deleted the lines
with - assuming it was a quasi patch. The resulting file still fails the
test under current gcc trunk as...

Setting LD_LIBRARY_PATH to .:/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/x86_64-apple-darwin10.7.0/./libstdc++-v3/src/.libs:/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/x86_64-apple-darwin10.7.0/./libstdc++-v3/src/.libs:/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/x86_64-apple-darwin10.7.0/./libobjc/.libs:/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/gcc:.:/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/x86_64-apple-darwin10.7.0/./libstdc++-v3/src/.libs:/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/x86_64-apple-darwin10.7.0/./libstdc++-v3/src/.libs:/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/x86_64-apple-darwin10.7.0/./libobjc/.libs:/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/gcc
Error - property_getAttributes ("long_property") returns "Tq,Vlong_property"
FAIL: obj-c++.dg/property/property-encoding-1.mm -fnext-runtime execution test
 
       Jack

>
Nicola Pero March 1, 2011, 1:50 p.m. UTC | #7
>> Can you replace that test with this one and let me know how it goes ? :-)
>
> Nicola,
>    The file you attached isn't a replacement property-encoding-1.m file.
> I manually changed the lines to + to remove those and deleted the lines
> with - assuming it was a quasi patch. The resulting file still fails the
> test under current gcc trunk as...

Thanks Jack,

on Sat, 26 Feb, 2011 at 16:46, you had responded to the same email saying --

> Nicola,
>   I can confirm that your replacement property-encoding-1.m eliminates the
> failures at -m64 on x86_64-apple-darwin10. Thanks for fixing that.

Can you just confirm which of the two is the case ? :-)

I was preparing to commit the revised testcase, but if it's still broken,
I obviously won't ;-)

Let me know, and thanks for your help :-)

Thanks
Jack Howarth March 1, 2011, 2:14 p.m. UTC | #8
On Tue, Mar 01, 2011 at 02:50:47PM +0100, Nicola Pero wrote:
> 
> >> Can you replace that test with this one and let me know how it goes ? :-)
> >
> > Nicola,
> >    The file you attached isn't a replacement property-encoding-1.m file.
> > I manually changed the lines to + to remove those and deleted the lines
> > with - assuming it was a quasi patch. The resulting file still fails the
> > test under current gcc trunk as...
> 
> Thanks Jack,
> 
> on Sat, 26 Feb, 2011 at 16:46, you had responded to the same email saying --
> 
> > Nicola,
> >   I can confirm that your replacement property-encoding-1.m eliminates the
> > failures at -m64 on x86_64-apple-darwin10. Thanks for fixing that.
> 
> Can you just confirm which of the two is the case ? :-)
> 
> I was preparing to commit the revised testcase, but if it's still broken,
> I obviously won't ;-)

I believe I may have accidentally done check-objc when I thought the second
revised testcase was passing so I was looking in the wrong testsuite.

> 
> Let me know, and thanks for your help :-)
> 
> Thanks
Jack Howarth March 2, 2011, 1:29 a.m. UTC | #9
On Tue, Mar 01, 2011 at 02:50:47PM +0100, Nicola Pero wrote:
> 
> >> Can you replace that test with this one and let me know how it goes ? :-)
> >
> > Nicola,
> >    The file you attached isn't a replacement property-encoding-1.m file.
> > I manually changed the lines to + to remove those and deleted the lines
> > with - assuming it was a quasi patch. The resulting file still fails the
> > test under current gcc trunk as...
> 
> Thanks Jack,
> 
> on Sat, 26 Feb, 2011 at 16:46, you had responded to the same email saying --
> 
> > Nicola,
> >   I can confirm that your replacement property-encoding-1.m eliminates the
> > failures at -m64 on x86_64-apple-darwin10. Thanks for fixing that.
> 
> Can you just confirm which of the two is the case ? :-)
> 
> I was preparing to commit the revised testcase, but if it's still broken,
> I obviously won't ;-)
> 
> Let me know, and thanks for your help :-)
> 
> Thanks

Nicola,
   Actually I am confused now. This testcase fix is regarding...

http://gcc.gnu.org/ml/gcc-patches/2011-02/msg01621.html
http://gcc.gnu.org/ml/gcc-patches/2011-02/msg01627.html

right? I just cleaned my tree and tried to reapply http://gcc.gnu.org/ml/gcc-patches/2011-02/txt00134.txt.
This produces...

patching file gcc/objc/objc-act.c
Reversed (or previously applied) patch detected!  Assume -R? [n] 
Apply anyway? [n] 

Is this the intended change in the original patch?
          Jack
diff mbox

Patch

Index: gcc/objc/ChangeLog
===================================================================
--- gcc/objc/ChangeLog	(revision 170489)
+++ gcc/objc/ChangeLog	(working copy)
@@ -1,3 +1,7 @@ 
+2011-02-25  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+	* objc-act.c (objc_v2_encode_prop_attr): Rewritten.
+	
 2011-02-23  Nicola Pero  <nicola.pero@meta-innovation.com>
 
 	* objc-act.c (build_private_template): Do not copy the
@@ -16,7 +20,8 @@ 
 
 2011-02-21  Mike Stump  <mikestump@comcast.net>
 
-	* Make-lang.in (check_objc_parallelize): Refine for 4 processor machines.
+	* Make-lang.in (check_objc_parallelize): Refine for 4 processor
+	machines.
 
 2011-02-20  Nicola Pero  <nicola.pero@meta-innovation.com>
 
Index: gcc/objc/objc-act.c
===================================================================
--- gcc/objc/objc-act.c	(revision 170489)
+++ gcc/objc/objc-act.c	(working copy)
@@ -10495,47 +10495,79 @@ 
      kPropertyGetter = 'G',
      kPropertySetter = 'S',
      kPropertyInstanceVariable = 'V',
-     kPropertyType = 't',
+     kPropertyType = 'T',
      kPropertyWeak = 'W',
-     kPropertyStrong = 'S',
+     kPropertyStrong = 'P',
      kPropertyNonAtomic = 'N'
-   };
-
-   FIXME: Update the implementation to match.  */
+   };  */
 tree
 objc_v2_encode_prop_attr (tree property)
 {
   const char *string;
   tree type = TREE_TYPE (property);
-  obstack_1grow (&util_obstack, 't');
+
+  obstack_1grow (&util_obstack, 'T');
   encode_type (type, obstack_object_size (&util_obstack),
 	       OBJC_ENCODE_INLINE_DEFS);
+
   if (PROPERTY_READONLY (property))
-    obstack_grow (&util_obstack, ",r", 2);
+    obstack_grow (&util_obstack, ",R", 2);
 
-  if (PROPERTY_ASSIGN_SEMANTICS (property) == OBJC_PROPERTY_COPY)
-    obstack_grow (&util_obstack, ",c", 2);
+  switch (PROPERTY_ASSIGN_SEMANTICS (property))
+    {
+    case OBJC_PROPERTY_COPY:
+      obstack_grow (&util_obstack, ",C", 2);
+      break;
+    case OBJC_PROPERTY_RETAIN:
+      obstack_grow (&util_obstack, ",&", 2);
+      break;
+    case OBJC_PROPERTY_ASSIGN:
+    default:
+      break;
+    }
 
-  if (PROPERTY_GETTER_NAME (property))
+  if (PROPERTY_DYNAMIC (property))
+    obstack_grow (&util_obstack, ",D", 2);    
+
+  if (PROPERTY_NONATOMIC (property))
+    obstack_grow (&util_obstack, ",N", 2);
+
+  /* Here we want to encode the getter name, but only if it's not the
+     standard one.  */
+  if (PROPERTY_GETTER_NAME (property) != PROPERTY_NAME (property))
     {
-      obstack_grow (&util_obstack, ",g", 2);
+      obstack_grow (&util_obstack, ",G", 2);
       string = IDENTIFIER_POINTER (PROPERTY_GETTER_NAME (property));
       obstack_grow (&util_obstack, string, strlen (string));
     }
-  if (PROPERTY_SETTER_NAME (property))
+
+  if (!PROPERTY_READONLY (property))
     {
-      obstack_grow (&util_obstack, ",s", 2);
-      string = IDENTIFIER_POINTER (PROPERTY_SETTER_NAME (property));
-      obstack_grow (&util_obstack, string, strlen (string));
+      /* Here we want to encode the setter name, but only if it's not
+	 the standard one.  */
+      tree standard_setter = get_identifier (objc_build_property_setter_name (PROPERTY_NAME (property)));
+      if (PROPERTY_SETTER_NAME (property) != standard_setter)
+	{
+	  obstack_grow (&util_obstack, ",S", 2);
+	  string = IDENTIFIER_POINTER (PROPERTY_SETTER_NAME (property));
+	  obstack_grow (&util_obstack, string, strlen (string));
+	}
     }
-  if (PROPERTY_IVAR_NAME (property))
+
+  /* TODO: Encode strong ('P'), weak ('W') for garbage collection.  */
+
+  if (!PROPERTY_DYNAMIC (property))
     {
-      obstack_grow (&util_obstack, ",i", 2);
-      string = IDENTIFIER_POINTER (PROPERTY_IVAR_NAME (property));
+      obstack_grow (&util_obstack, ",V", 2);
+      if (PROPERTY_IVAR_NAME (property))
+	string = IDENTIFIER_POINTER (PROPERTY_IVAR_NAME (property));
+      else
+	string = IDENTIFIER_POINTER (PROPERTY_NAME (property));
       obstack_grow (&util_obstack, string, strlen (string));
     }
-    
-  obstack_1grow (&util_obstack, 0);    /* null terminate string */
+
+  /* NULL-terminate string.  */
+  obstack_1grow (&util_obstack, 0);
   string = XOBFINISH (&util_obstack, char *);
   obstack_free (&util_obstack, util_firstobj);
   return get_identifier (string);
Index: gcc/testsuite/ChangeLog
===================================================================
--- gcc/testsuite/ChangeLog	(revision 170489)
+++ gcc/testsuite/ChangeLog	(working copy)
@@ -1,3 +1,11 @@ 
+2011-02-25  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+	* objc.dg/gnu-api-2-property.m: Added tests for property_getName()
+	and property_getAttributes() if __OBJC2__.
+	* obj-c++.dg/gnu-api-2-property.mm: Likewise.
+	* objc.dg/property/property-encoding-1.m: New.
+	* obj-c++.dg/property/property-encoding-1.mm: New.
+
 2011-02-24  Jason Merrill  <jason@redhat.com>
 
 	* g++.dg/parse/constant1.C: Specify C++98 mode.
Index: gcc/testsuite/objc.dg/property/property-encoding-1.m
===================================================================
--- gcc/testsuite/objc.dg/property/property-encoding-1.m	(revision 0)
+++ gcc/testsuite/objc.dg/property/property-encoding-1.m	(revision 0)
@@ -0,0 +1,160 @@ 
+/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, February 2011.  */
+/* Test encoding properties.  */
+/* { dg-do run } */
+/* { dg-skip-if "No API#2 pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */
+
+#include <objc/runtime.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+@interface MyRootClass
+{ Class isa; }
++ alloc;
+- init;
++ initialize;
+@end
+
+@implementation MyRootClass
++ alloc { return class_createInstance (self, 0); }
+- init  { return self; }
++ initialize { return self; }
+@end
+
+@interface MySubClass : MyRootClass
+{
+  char char_property;
+  short short_property;
+  int int_property;
+  long long_property;
+  float float_property;
+  double double_property;
+  int *int_pointer_property;
+
+  id propertyA;
+  id propertyB;
+  id propertyC;
+  id propertyD;
+  int propertyE;
+  id propertyF;
+
+  id other_variable;
+}
+@property char char_property;
+@property short short_property;
+@property int int_property;
+@property long long_property;
+@property float float_property;
+@property double double_property;
+@property int *int_pointer_property;
+
+@property (assign, getter=getP, setter=setP:) id propertyA;
+@property (assign) id propertyB;
+@property (copy) id propertyC;
+@property (retain) id propertyD;
+@property (nonatomic) int propertyE;
+@property (nonatomic, readonly, copy) id propertyF;
+
+@property (assign) id propertyG;
+@property (assign, readonly, getter=X) id propertyH;
+@end
+
+@implementation MySubClass
+@synthesize char_property;
+@synthesize short_property;
+@synthesize int_property;
+@synthesize long_property;
+@synthesize float_property;
+@synthesize double_property;
+@synthesize int_pointer_property;
+
+@synthesize propertyA;
+@synthesize propertyB;
+@synthesize propertyC;
+@synthesize propertyD;
+@synthesize propertyE;
+@synthesize propertyF;
+
+@synthesize propertyG = other_variable;
+@dynamic propertyH;
+@end
+
+#ifdef __OBJC2__
+void error (objc_property_t p)
+{
+  printf ("Error - property_getAttributes (\"%s\") returns \"%s\"\n",
+	  property_getName (p),
+	  property_getAttributes (p));
+  abort ();
+}
+#endif
+
+int main(int argc, void **args)
+{
+#ifdef __OBJC2__
+  Class c = objc_getClass ("MySubClass");
+  objc_property_t p;
+
+  p = class_getProperty (c, "char_property");
+  if (strcmp ("Tc,Vchar_property", property_getAttributes (p)) != 0)
+    error (p);
+
+  p = class_getProperty (c, "short_property");
+  if (strcmp ("Ts,Vshort_property", property_getAttributes (p)) != 0)
+    error (p);
+
+  p = class_getProperty (c, "int_property");
+  if (strcmp ("Ti,Vint_property", property_getAttributes (p)) != 0)
+    error (p);
+
+  p = class_getProperty (c, "long_property");
+  if (strcmp ("Tl,Vlong_property", property_getAttributes (p)) != 0)
+    error (p);
+
+  p = class_getProperty (c, "float_property");
+  if (strcmp ("Tf,Vfloat_property", property_getAttributes (p)) != 0)
+    error (p);
+
+  p = class_getProperty (c, "double_property");
+  if (strcmp ("Td,Vdouble_property", property_getAttributes (p)) != 0)
+    error (p);
+
+  p = class_getProperty (c, "int_pointer_property");
+  if (strcmp ("T^i,Vint_pointer_property", property_getAttributes (p)) != 0)
+    error (p);
+
+  p = class_getProperty (c, "propertyA");
+  if (strcmp ("T@,GgetP,SsetP:,VpropertyA", property_getAttributes (p)) != 0)
+    error (p);
+
+  p = class_getProperty (c, "propertyB");
+  if (strcmp ("T@,VpropertyB", property_getAttributes (p)) != 0)
+    error (p);
+
+  p = class_getProperty (c, "propertyC");
+  if (strcmp ("T@,C,VpropertyC", property_getAttributes (p)) != 0)
+    error (p);
+
+  p = class_getProperty (c, "propertyD");
+  if (strcmp ("T@,&,VpropertyD", property_getAttributes (p)) != 0)
+    error (p);
+
+  p = class_getProperty (c, "propertyE");
+  if (strcmp ("Ti,N,VpropertyE", property_getAttributes (p)) != 0)
+    error (p);
+
+  p = class_getProperty (c, "propertyF");
+  if (strcmp ("T@,R,C,N,VpropertyF", property_getAttributes (p)) != 0)
+    error (p);
+
+  p = class_getProperty (c, "propertyG");
+  if (strcmp ("T@,Vother_variable", property_getAttributes (p)) != 0)
+    error (p);
+
+  p = class_getProperty (c, "propertyH");
+  if (strcmp ("T@,R,D,GX", property_getAttributes (p)) != 0)
+    error (p);
+#endif
+
+  return 0;
+}
Index: gcc/testsuite/objc.dg/gnu-api-2-property.m
===================================================================
--- gcc/testsuite/objc.dg/gnu-api-2-property.m	(revision 170489)
+++ gcc/testsuite/objc.dg/gnu-api-2-property.m	(working copy)
@@ -25,23 +25,18 @@ 
 + initialize { return self; }
 @end
 
-@protocol MyProtocol
-- (id) variable;
+@interface MySubClass : MyRootClass
+{
+  id propertyA;
+  id propertyB;
+}
+@property (assign, getter=getP, setter=setP:) id propertyA;
+@property (assign, nonatomic) id propertyB;
 @end
 
-@protocol MySecondProtocol
-- (id) setVariable: (id)value;
-@end
-
-@interface MySubClass : MyRootClass <MyProtocol>
-{ id variable_ivar; }
-- (void) setVariable: (id)value;
-- (id) variable;
-@end
-
 @implementation MySubClass
-- (void) setVariable: (id)value { variable_ivar = value; }
-- (id) variable { return variable_ivar; }
+@synthesize propertyA;
+@synthesize propertyB;
 @end
 
 
@@ -49,7 +44,6 @@ 
 {
   /* Functions are tested in alphabetical order.  */
 
-  /* TODO: Test new ABI (when available).  */
   printf ("Testing property_getAttributes () ...\n");
   {
     /* The Apple/NeXT runtime seems to crash on the following.  */
@@ -57,9 +51,26 @@ 
     if (property_getAttributes (NULL) != NULL)
       abort ();
 #endif
+
+    /* The GNU runtime doesn't support looking up properties at
+       runtime yet.  */
+#ifdef __OBJC2__
+    {
+      objc_property_t property;
+      
+      property = class_getProperty (objc_getClass ("MySubClass"), "propertyA");
+      if (strcmp (property_getAttributes (property),
+		  "T@,GgetP,SsetP:,VpropertyA") != 0)
+	abort ();
+
+      property = class_getProperty (objc_getClass ("MySubClass"), "propertyB");
+      if (strcmp (property_getAttributes (property),
+		  "T@,N,VpropertyB") != 0)
+	abort ();
+    }
+#endif    
   }
 
-  /* TODO: Test new ABI (when available).  */
   printf ("Testing property_getName () ...\n");
   {
     /* The Apple/NeXT runtime seems to crash on the following.  */
@@ -67,6 +78,22 @@ 
     if (property_getName (NULL) != NULL)
       abort ();
 #endif
+
+    /* The GNU runtime doesn't support looking up properties at
+       runtime yet.  */
+#ifdef __OBJC2__
+    {
+      objc_property_t property;
+      
+      property = class_getProperty (objc_getClass ("MySubClass"), "propertyA");
+      if (strcmp (property_getName (property), "propertyA") != 0)
+	abort ();
+
+      property = class_getProperty (objc_getClass ("MySubClass"), "propertyB");
+      if (strcmp (property_getName (property), "propertyB") != 0)
+	abort ();
+    }
+#endif
   }
 
   return 0;
Index: gcc/testsuite/obj-c++.dg/property/property-encoding-1.mm
===================================================================
--- gcc/testsuite/obj-c++.dg/property/property-encoding-1.mm	(revision 0)
+++ gcc/testsuite/obj-c++.dg/property/property-encoding-1.mm	(revision 0)
@@ -0,0 +1,160 @@ 
+/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, February 2011.  */
+/* Test encoding properties.  */
+/* { dg-do run } */
+/* { dg-skip-if "No API#2 pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */
+
+#include <objc/runtime.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+@interface MyRootClass
+{ Class isa; }
++ alloc;
+- init;
++ initialize;
+@end
+
+@implementation MyRootClass
++ alloc { return class_createInstance (self, 0); }
+- init  { return self; }
++ initialize { return self; }
+@end
+
+@interface MySubClass : MyRootClass
+{
+  char char_property;
+  short short_property;
+  int int_property;
+  long long_property;
+  float float_property;
+  double double_property;
+  int *int_pointer_property;
+
+  id propertyA;
+  id propertyB;
+  id propertyC;
+  id propertyD;
+  int propertyE;
+  id propertyF;
+
+  id other_variable;
+}
+@property char char_property;
+@property short short_property;
+@property int int_property;
+@property long long_property;
+@property float float_property;
+@property double double_property;
+@property int *int_pointer_property;
+
+@property (assign, getter=getP, setter=setP:) id propertyA;
+@property (assign) id propertyB;
+@property (copy) id propertyC;
+@property (retain) id propertyD;
+@property (nonatomic) int propertyE;
+@property (nonatomic, readonly, copy) id propertyF;
+
+@property (assign) id propertyG;
+@property (assign, readonly, getter=X) id propertyH;
+@end
+
+@implementation MySubClass
+@synthesize char_property;
+@synthesize short_property;
+@synthesize int_property;
+@synthesize long_property;
+@synthesize float_property;
+@synthesize double_property;
+@synthesize int_pointer_property;
+
+@synthesize propertyA;
+@synthesize propertyB;
+@synthesize propertyC;
+@synthesize propertyD;
+@synthesize propertyE;
+@synthesize propertyF;
+
+@synthesize propertyG = other_variable;
+@dynamic propertyH;
+@end
+
+#ifdef __OBJC2__
+void error (objc_property_t p)
+{
+  printf ("Error - property_getAttributes (\"%s\") returns \"%s\"\n",
+	  property_getName (p),
+	  property_getAttributes (p));
+  abort ();
+}
+#endif
+
+int main(int argc, char **args)
+{
+#ifdef __OBJC2__
+  Class c = objc_getClass ("MySubClass");
+  objc_property_t p;
+
+  p = class_getProperty (c, "char_property");
+  if (strcmp ("Tc,Vchar_property", property_getAttributes (p)) != 0)
+    error (p);
+
+  p = class_getProperty (c, "short_property");
+  if (strcmp ("Ts,Vshort_property", property_getAttributes (p)) != 0)
+    error (p);
+
+  p = class_getProperty (c, "int_property");
+  if (strcmp ("Ti,Vint_property", property_getAttributes (p)) != 0)
+    error (p);
+
+  p = class_getProperty (c, "long_property");
+  if (strcmp ("Tl,Vlong_property", property_getAttributes (p)) != 0)
+    error (p);
+
+  p = class_getProperty (c, "float_property");
+  if (strcmp ("Tf,Vfloat_property", property_getAttributes (p)) != 0)
+    error (p);
+
+  p = class_getProperty (c, "double_property");
+  if (strcmp ("Td,Vdouble_property", property_getAttributes (p)) != 0)
+    error (p);
+
+  p = class_getProperty (c, "int_pointer_property");
+  if (strcmp ("T^i,Vint_pointer_property", property_getAttributes (p)) != 0)
+    error (p);
+
+  p = class_getProperty (c, "propertyA");
+  if (strcmp ("T@,GgetP,SsetP:,VpropertyA", property_getAttributes (p)) != 0)
+    error (p);
+
+  p = class_getProperty (c, "propertyB");
+  if (strcmp ("T@,VpropertyB", property_getAttributes (p)) != 0)
+    error (p);
+
+  p = class_getProperty (c, "propertyC");
+  if (strcmp ("T@,C,VpropertyC", property_getAttributes (p)) != 0)
+    error (p);
+
+  p = class_getProperty (c, "propertyD");
+  if (strcmp ("T@,&,VpropertyD", property_getAttributes (p)) != 0)
+    error (p);
+
+  p = class_getProperty (c, "propertyE");
+  if (strcmp ("Ti,N,VpropertyE", property_getAttributes (p)) != 0)
+    error (p);
+
+  p = class_getProperty (c, "propertyF");
+  if (strcmp ("T@,R,C,N,VpropertyF", property_getAttributes (p)) != 0)
+    error (p);
+
+  p = class_getProperty (c, "propertyG");
+  if (strcmp ("T@,Vother_variable", property_getAttributes (p)) != 0)
+    error (p);
+
+  p = class_getProperty (c, "propertyH");
+  if (strcmp ("T@,R,D,GX", property_getAttributes (p)) != 0)
+    error (p);
+#endif
+
+  return 0;
+}
Index: gcc/testsuite/obj-c++.dg/gnu-api-2-property.mm
===================================================================
--- gcc/testsuite/obj-c++.dg/gnu-api-2-property.mm	(revision 170489)
+++ gcc/testsuite/obj-c++.dg/gnu-api-2-property.mm	(working copy)
@@ -25,23 +25,18 @@ 
 + initialize { return self; }
 @end
 
-@protocol MyProtocol
-- (id) variable;
+@interface MySubClass : MyRootClass
+{
+  id propertyA;
+  id propertyB;
+}
+@property (assign, getter=getP, setter=setP:) id propertyA;
+@property (assign, nonatomic) id propertyB;
 @end
 
-@protocol MySecondProtocol
-- (id) setVariable: (id)value;
-@end
-
-@interface MySubClass : MyRootClass <MyProtocol>
-{ id variable_ivar; }
-- (void) setVariable: (id)value;
-- (id) variable;
-@end
-
 @implementation MySubClass
-- (void) setVariable: (id)value { variable_ivar = value; }
-- (id) variable { return variable_ivar; }
+@synthesize propertyA;
+@synthesize propertyB;
 @end
 
 
@@ -49,7 +44,6 @@ 
 {
   /* Functions are tested in alphabetical order.  */
 
-  /* TODO: Test new ABI (when available).  */
   std::cout << "Testing property_getAttributes () ...\n";
   {
     /* The Apple/NeXT runtime seems to crash on the following.  */
@@ -57,9 +51,26 @@ 
     if (property_getAttributes (NULL) != NULL)
       abort ();
 #endif
+
+    /* The GNU runtime doesn't support looking up properties at
+       runtime yet.  */
+#ifdef __OBJC2__
+    {
+      objc_property_t property;
+      
+      property = class_getProperty (objc_getClass ("MySubClass"), "propertyA");
+      if (std::strcmp (property_getAttributes (property),
+		  "T@,GgetP,SsetP:,VpropertyA") != 0)
+	abort ();
+
+      property = class_getProperty (objc_getClass ("MySubClass"), "propertyB");
+      if (std::strcmp (property_getAttributes (property),
+		  "T@,N,VpropertyB") != 0)
+	abort ();
+    }
+#endif    
   }
 
-  /* TODO: Test new ABI (when available).  */
   std::cout << "Testing property_getName () ...\n";
   {
     /* The Apple/NeXT runtime seems to crash on the following.  */
@@ -68,6 +79,22 @@ 
     if (property_getName (NULL) != NULL)
       abort ();
 #endif
+
+    /* The GNU runtime doesn't support looking up properties at
+       runtime yet.  */
+#ifdef __OBJC2__
+    {
+      objc_property_t property;
+      
+      property = class_getProperty (objc_getClass ("MySubClass"), "propertyA");
+      if (std::strcmp (property_getName (property), "propertyA") != 0)
+	abort ();
+
+      property = class_getProperty (objc_getClass ("MySubClass"), "propertyB");
+      if (std::strcmp (property_getName (property), "propertyB") != 0)
+	abort ();
+    }
+#endif
   }
 
   return (0);