summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Parse/ParseDecl.cpp10
-rw-r--r--test/Parser/attributes.c12
2 files changed, 15 insertions, 7 deletions
diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp
index 2c9045d74a..0b57c8ab66 100644
--- a/lib/Parse/ParseDecl.cpp
+++ b/lib/Parse/ParseDecl.cpp
@@ -164,10 +164,10 @@ void Parser::ParseGNUAttributes(ParsedAttributes &attrs,
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(ParsedAttributes &attrs,
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);
diff --git a/test/Parser/attributes.c b/test/Parser/attributes.c
index b815b8da3d..26ece79ddc 100644
--- a/test/Parser/attributes.c
+++ b/test/Parser/attributes.c
@@ -59,8 +59,8 @@ void __attribute__((returns_twice)) returns_twice_test();
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);