diff mbox series

Objective-C/C++ (C-family) : Add missing 'atomic' property attribute.

Message ID BD4A551F-2A53-4CA9-942F-397A8A7928B1@sandoe.co.uk
State New
Headers show
Series Objective-C/C++ (C-family) : Add missing 'atomic' property attribute. | expand

Commit Message

Iain Sandoe Nov. 6, 2020, 8:22 p.m. UTC
Hi

Arguably, this is actually a bug fix since the ‘atomic’ attribute is
paired with the ‘nonatomic’ one.  However it is the default and was
omitted when the @property implementation was added.

‘atomic’ in Objective-C terms is not specified in relation to _Atomic
or std::atomic (the _Atomic keyword is not accepted in that context).

tested across several Darwin versions and on x86_64-linux-gnu

OK for the C-family parts?
thanks
Iain

--------

This is the default, but it is still legal in user code and therefore
we should handle it in parsing.  Fix whitespace issues in the lines
affected.

gcc/c-family/ChangeLog:

	* c-common.c (c_common_reswords): Add 'atomic' property
	attribute.
	* c-common.h (enum rid): Add RID_PROPATOMIC for atomic
	property attributes.

gcc/testsuite/ChangeLog:

	* obj-c++.dg/property/at-property-4.mm: Test atomic property
	attribute.
	* objc.dg/property/at-property-4.m: Likewise.
---
 gcc/c-family/c-common.c                         | 17 +++++++++--------
 gcc/c-family/c-common.h                         |  2 +-
 gcc/objc/objc-act.c                             |  1 +
 .../obj-c++.dg/property/at-property-4.mm        |  3 +++
 gcc/testsuite/objc.dg/property/at-property-4.m  |  3 +++
 5 files changed, 17 insertions(+), 9 deletions(-)

Comments

Joseph Myers Nov. 6, 2020, 10:01 p.m. UTC | #1
On Fri, 6 Nov 2020, Iain Sandoe wrote:

> Hi
> 
> Arguably, this is actually a bug fix since the ‘atomic’ attribute is
> paired with the ‘nonatomic’ one.  However it is the default and was
> omitted when the @property implementation was added.
> 
> ‘atomic’ in Objective-C terms is not specified in relation to _Atomic
> or std::atomic (the _Atomic keyword is not accepted in that context).
> 
> tested across several Darwin versions and on x86_64-linux-gnu
> 
> OK for the C-family parts?

OK.

(_Atomic isn't accepted for Objective-C at all at present; see the comment 
on the relevant sorry in c-parser.c.)
diff mbox series

Patch

diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 9302a2461d4..d4d3228b8f6 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -571,14 +571,15 @@  const struct c_common_resword c_common_reswords[] =
   { "oneway",		RID_ONEWAY,		D_OBJC },
   { "out",		RID_OUT,		D_OBJC },
   /* These are recognized inside a property attribute list */
-  { "assign",	        RID_ASSIGN,		D_OBJC }, 
-  { "copy",	        RID_COPY,		D_OBJC }, 
-  { "getter",		RID_GETTER,		D_OBJC }, 
-  { "nonatomic",	RID_NONATOMIC,		D_OBJC }, 
-  { "readonly",		RID_READONLY,		D_OBJC }, 
-  { "readwrite",	RID_READWRITE,		D_OBJC }, 
-  { "retain",	        RID_RETAIN,		D_OBJC }, 
-  { "setter",		RID_SETTER,		D_OBJC }, 
+  { "assign",		RID_ASSIGN,		D_OBJC },
+  { "atomic",		RID_PROPATOMIC,		D_OBJC },
+  { "copy",		RID_COPY,		D_OBJC },
+  { "getter",		RID_GETTER,		D_OBJC },
+  { "nonatomic",	RID_NONATOMIC,		D_OBJC },
+  { "readonly",		RID_READONLY,		D_OBJC },
+  { "readwrite",	RID_READWRITE,		D_OBJC },
+  { "retain",		RID_RETAIN,		D_OBJC },
+  { "setter",		RID_SETTER,		D_OBJC },
 };
 
 const unsigned int num_c_common_reswords =
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index 18b489d55a3..7e2cd5342aa 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -85,7 +85,7 @@  enum rid
   RID_GETTER, RID_SETTER,
   RID_READONLY, RID_READWRITE,
   RID_ASSIGN, RID_RETAIN, RID_COPY,
-  RID_NONATOMIC,
+  RID_PROPATOMIC, RID_NONATOMIC,
 
   /* C (reserved and imaginary types not implemented, so any use is a
      syntax error) */
diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c
index 8be4beadf3b..2dad46aa77e 100644
--- a/gcc/objc/objc-act.c
+++ b/gcc/objc/objc-act.c
@@ -822,6 +822,7 @@  objc_prop_attr_kind_for_rid (enum rid prop_rid)
       case RID_RETAIN:		return OBJC_PROPERTY_ATTR_RETAIN;
       case RID_COPY:		return OBJC_PROPERTY_ATTR_COPY;
 
+      case RID_PROPATOMIC:	return OBJC_PROPERTY_ATTR_ATOMIC;
       case RID_NONATOMIC:	return OBJC_PROPERTY_ATTR_NONATOMIC;
 
     }
diff --git a/gcc/testsuite/obj-c++.dg/property/at-property-4.mm b/gcc/testsuite/obj-c++.dg/property/at-property-4.mm
index 4083947de71..31f2eb4336a 100644
--- a/gcc/testsuite/obj-c++.dg/property/at-property-4.mm
+++ b/gcc/testsuite/obj-c++.dg/property/at-property-4.mm
@@ -16,6 +16,7 @@ 
 /* Test that all the new property attributes can be parsed.  */
 @property (assign)    id property_a;
 @property (copy)      id property_b;
+@property (atomic)    int property_ca;
 @property (nonatomic) int property_c;
 @property (readonly)  int property_d;
 @property (readwrite) int property_e;
@@ -34,6 +35,8 @@ 
 @property (assign, copy) id d;            /* { dg-error ".copy. attribute conflicts with .assign. attribute" } */
 @property (copy, retain) id e;            /* { dg-error ".retain. attribute conflicts with .copy. attribute" } */
 
+@property (atomic, nonatomic) int property_j; /* { dg-error {'nonatomic' attribute conflicts with 'atomic' attribute} } */
+
 @property (setter=mySetter:,setter=mySetter2:)  int f; /* { dg-warning {multiple property 'setter' methods specified, the latest one will be used} } */
 @property (getter=myGetter, getter=myGetter2 )  int g; /* { dg-warning {multiple property 'getter' methods specified, the latest one will be used} } */
 
diff --git a/gcc/testsuite/objc.dg/property/at-property-4.m b/gcc/testsuite/objc.dg/property/at-property-4.m
index 4083947de71..31f2eb4336a 100644
--- a/gcc/testsuite/objc.dg/property/at-property-4.m
+++ b/gcc/testsuite/objc.dg/property/at-property-4.m
@@ -16,6 +16,7 @@ 
 /* Test that all the new property attributes can be parsed.  */
 @property (assign)    id property_a;
 @property (copy)      id property_b;
+@property (atomic)    int property_ca;
 @property (nonatomic) int property_c;
 @property (readonly)  int property_d;
 @property (readwrite) int property_e;
@@ -34,6 +35,8 @@ 
 @property (assign, copy) id d;            /* { dg-error ".copy. attribute conflicts with .assign. attribute" } */
 @property (copy, retain) id e;            /* { dg-error ".retain. attribute conflicts with .copy. attribute" } */
 
+@property (atomic, nonatomic) int property_j; /* { dg-error {'nonatomic' attribute conflicts with 'atomic' attribute} } */
+
 @property (setter=mySetter:,setter=mySetter2:)  int f; /* { dg-warning {multiple property 'setter' methods specified, the latest one will be used} } */
 @property (getter=myGetter, getter=myGetter2 )  int g; /* { dg-warning {multiple property 'getter' methods specified, the latest one will be used} } */