This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C PATCH] Warn for _Alignas in an array declarator (PR c/58267)


On Sat, Oct 19, 2013 at 07:23:20PM +0000, Joseph S. Myers wrote:
> On Wed, 16 Oct 2013, Marek Polacek wrote:
> 
> > @@ -2946,7 +2957,8 @@ c_parser_declarator (c_parser *parser, b
> >        struct c_declspecs *quals_attrs = build_null_declspecs ();
> >        struct c_declarator *inner;
> >        c_parser_consume_token (parser);
> > -      c_parser_declspecs (parser, quals_attrs, false, false, true, cla_prefer_id);
> > +      c_parser_declspecs (parser, quals_attrs, false, false, true,
> > +			  true, cla_prefer_id);
> >        inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
> >        if (inner == NULL)
> >  	return NULL;
> 
> Looking at this again, shouldn't the new argument be "false" (with 
> associated testcase)?  This is parsing pointer declarators, and _Alignas 
> isn't allowed there any more than it is in array declarators....

Ah, yeah, I think so, fixed & testcase added.  Thanks for catching it.
 
> > @@ -3715,7 +3730,8 @@ c_parser_type_name (c_parser *parser)
> >    struct c_declarator *declarator;
> >    struct c_type_name *ret;
> >    bool dummy = false;
> > -  c_parser_declspecs (parser, specs, false, true, true, cla_prefer_type);
> > +  c_parser_declspecs (parser, specs, false, true, true, false,
> > +		      cla_prefer_type);
> >    if (!specs->declspecs_seen_p)
> >      {
> >        c_parser_error (parser, "expected specifier-qualifier-list");
> 
> And this should get a testcase added, that _Alignas is correctly rejected 
> in type names where previously it would have been wrongly accepted.

I added the tests.
 
> (Strictly by the standard it should be "false" in 
> c_parser_struct_declaration as well - the syntax there doesn't allow 
> _Alignas - but it appears to have been intended to allow it there, so 
> probably best not to change anything there until WG14 reaches a conclusion 
> on the issues I raised in N1731.)

I added a comment there to that effect.

Tested via make check -C gcc RUNTESTFLAGS=dg.exp=c1x-*.c, ok for
trunk?

2013-10-21  Marek Polacek  <polacek@redhat.com>

c/
	* c-parser.c (c_parser_struct_declaration): Add a comment.
	(c_parser_declarator): Don't allow _Alignas here.
testsuite/
	* gcc.dg/c1x-align-5.c: Add more testing.

--- gcc/c/c-parser.c.mp	2013-10-21 19:34:17.877539421 +0200
+++ gcc/c/c-parser.c	2013-10-21 20:22:45.980220027 +0200
@@ -2645,6 +2645,11 @@ c_parser_struct_declaration (c_parser *p
     }
   specs = build_null_declspecs ();
   decl_loc = c_parser_peek_token (parser)->location;
+  /* Strictly by the standard, we shouldn't allow _Alignas here,
+     but it appears to have been intended to allow it there, so
+     we're keeping it as it is until WG14 reaches a conclusion
+     of N1731.
+     <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf>  */
   c_parser_declspecs (parser, specs, false, true, true,
 		      true, cla_nonabstract_decl);
   if (parser->error)
@@ -2959,7 +2964,7 @@ c_parser_declarator (c_parser *parser, b
       struct c_declarator *inner;
       c_parser_consume_token (parser);
       c_parser_declspecs (parser, quals_attrs, false, false, true,
-			  true, cla_prefer_id);
+			  false, cla_prefer_id);
       inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
       if (inner == NULL)
 	return NULL;
--- gcc/testsuite/gcc.dg/c1x-align-5.c.mp	2013-10-21 19:41:20.088041095 +0200
+++ gcc/testsuite/gcc.dg/c1x-align-5.c	2013-10-21 20:16:55.096984545 +0200
@@ -14,6 +14,14 @@ void foo (int a[_Alignas (0) 10]) { } /*
 void
 test (void)
 {
+  int *_Alignas (long) p; /* { dg-error "expected" } */
+  int *const _Alignas (long) *q; /* { dg-error "expected" } */
+  struct s { int n; };
+  __builtin_offsetof (struct s _Alignas (int), n); /* { dg-error "expected" } */
+  __typeof (long double _Alignas (0)) e; /* { dg-error "expected" } */
+  sizeof (int _Alignas (int)); /* { dg-error "expected" } */
+  _Alignas (int _Alignas (float)) int t; /* { dg-error "expected" } */
+  __builtin_types_compatible_p (signed _Alignas (0), unsigned); /* { dg-error "expected" } */
   int a[_Alignas (int) 10]; /* { dg-error "expected expression before" } */
   int b[10];
   foo (b);

	Marek


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]