C PATCH for c/82679 (rejects-valid with _Atomic and arrays)

Message ID 20171210174820.GA2605@redhat.com
State New
Headers show
Series
  • C PATCH for c/82679 (rejects-valid with _Atomic and arrays)
Related show

Commit Message

Marek Polacek Dec. 10, 2017, 5:48 p.m.
We were wrongly rejecting code in the attached test because the check
in grokdeclarator is wrong: we only want to check whether the user is
trying to apply _Atomic to an array type, i.e. this:

typedef int T[10];
_Atomic T a;

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2017-12-10  Marek Polacek  <polacek@redhat.com>

	PR c/82679
	* c-decl.c (grokdeclarator): Check declspecs insted of atomicp.

	* gcc.dg/c11-atomic-5.c: New test.


	Marek

Comments

Jeff Law Dec. 11, 2017, 10:49 p.m. | #1
On 12/10/2017 10:48 AM, Marek Polacek wrote:
> We were wrongly rejecting code in the attached test because the check

> in grokdeclarator is wrong: we only want to check whether the user is

> trying to apply _Atomic to an array type, i.e. this:

> 

> typedef int T[10];

> _Atomic T a;

> 

> Bootstrapped/regtested on x86_64-linux, ok for trunk?

> 

> 2017-12-10  Marek Polacek  <polacek@redhat.com>

> 

> 	PR c/82679

> 	* c-decl.c (grokdeclarator): Check declspecs insted of atomicp.

> 

> 	* gcc.dg/c11-atomic-5.c: New test.

OK.
jeff

Patch

--- gcc/c/c-decl.c
+++ gcc/c/c-decl.c
@@ -5813,7 +5813,7 @@  grokdeclarator (const struct c_declarator *declarator,
      of typedefs or typeof) must be detected here.  If the qualifier
      is introduced later, any appearance of applying it to an array is
      actually applying it to an element of that array.  */
-  if (atomicp && TREE_CODE (type) == ARRAY_TYPE)
+  if (declspecs->atomic_p && TREE_CODE (type) == ARRAY_TYPE)
     error_at (loc, "%<_Atomic%>-qualified array type");
 
   /* Warn about storage classes that are invalid for certain
--- gcc/testsuite/gcc.dg/c11-atomic-5.c
+++ gcc/testsuite/gcc.dg/c11-atomic-5.c
@@ -0,0 +1,10 @@ 
+/* PR c/82679 */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu11" } */
+
+typedef _Atomic int A[10];
+A a;
+
+typedef _Atomic int I;
+typedef I T[10];
+T t;