r363676 - Require commas to separate multiple GNU-style attributes in the same attribute list.

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 18 05:57:06 PDT 2019


Author: aaronballman
Date: Tue Jun 18 05:57:05 2019
New Revision: 363676

URL: http://llvm.org/viewvc/llvm-project?rev=363676&view=rev
Log:
Require commas to separate multiple GNU-style attributes in the same attribute list.

Fixes PR38352.

Modified:
    cfe/trunk/lib/Parse/ParseDecl.cpp
    cfe/trunk/test/Parser/attributes.c

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=363676&r1=363675&r2=363676&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Tue Jun 18 05:57:05 2019
@@ -164,10 +164,10 @@ void Parser::ParseGNUAttributes(ParsedAt
       return;
     }
     // Parse the attribute-list. e.g. __attribute__(( weak, alias("__f") ))
-    while (true) {
-      // Allow empty/non-empty attributes. ((__vector_size__(16),,,,))
-      if (TryConsumeToken(tok::comma))
-        continue;
+    do {
+      // Eat preceeding commas to allow __attribute__((,,,foo))
+      while (TryConsumeToken(tok::comma))
+        ;
 
       // Expect an identifier or declaration specifier (const, int, etc.)
       if (Tok.isAnnotation())
@@ -212,7 +212,7 @@ void Parser::ParseGNUAttributes(ParsedAt
       Eof.startToken();
       Eof.setLocation(Tok.getLocation());
       LA->Toks.push_back(Eof);
-    }
+    } while (Tok.is(tok::comma));
 
     if (ExpectAndConsume(tok::r_paren))
       SkipUntil(tok::r_paren, StopAtSemi);

Modified: cfe/trunk/test/Parser/attributes.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/attributes.c?rev=363676&r1=363675&r2=363676&view=diff
==============================================================================
--- cfe/trunk/test/Parser/attributes.c (original)
+++ cfe/trunk/test/Parser/attributes.c Tue Jun 18 05:57:05 2019
@@ -59,8 +59,8 @@ void __attribute__((returns_twice)) retu
 
 int aligned(int);
 int __attribute__((vec_type_hint(char, aligned(16) )) missing_rparen_1; // expected-error 2{{expected ')'}} expected-note {{to match}} expected-warning {{does not declare anything}}
-int __attribute__((mode(x aligned(16) )) missing_rparen_2; // expected-error {{expected ')'}}
-int __attribute__((format(printf, 0 aligned(16) )) missing_rparen_3; // expected-error {{expected ')'}}
+int __attribute__((mode(x aligned(16) )) missing_rparen_2; // expected-error 2{{expected ')'}}
+int __attribute__((format(printf, 0 aligned(16) )) missing_rparen_3; // expected-error 2{{expected ')'}}
 
 
 
@@ -105,3 +105,11 @@ struct s {
 // specifier.
 struct s
 __attribute__((used)) bar;
+
+// Ensure that attributes must be separated by a comma (PR38352).
+__attribute__((const const)) int PR38352(void); // expected-error {{expected ')'}}
+// Also ensure that we accept spurious commas.
+__attribute__((,,,const)) int PR38352_1(void);
+__attribute__((const,,,)) int PR38352_2(void);
+__attribute__((const,,,const)) int PR38352_3(void);
+__attribute__((,,,const,,,const,,,)) int PR38352_4(void);




More information about the cfe-commits mailing list