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

Fixes PR38352.

llvm-svn: 363676
This commit is contained in:
Aaron Ballman 2019-06-18 12:57:05 +00:00
parent f39f3bd056
commit 7a89909c84
2 changed files with 15 additions and 7 deletions

View File

@ -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);

View File

@ -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);