Parse: Diagnose malformed 'message' arguments for 'availability' attr

The parsing code for 'availability' wasn't prepared for string literals
like "a" L"b" showing up.  Error if this occurs.

llvm-svn: 213350
This commit is contained in:
David Majnemer 2014-07-18 05:43:12 +00:00
parent a5d2a49c34
commit 2e49830b3d
2 changed files with 14 additions and 1 deletions

View File

@ -825,13 +825,24 @@ void Parser::ParseAvailabilityAttribute(IdentifierInfo &Availability,
}
ConsumeToken();
if (Keyword == Ident_message) {
if (Tok.isNot(tok::string_literal)) { // Also reject wide string literals.
if (Tok.isNot(tok::string_literal)) {
Diag(Tok, diag::err_expected_string_literal)
<< /*Source='availability attribute'*/2;
SkipUntil(tok::r_paren, StopAtSemi);
return;
}
MessageExpr = ParseStringLiteralExpression();
// Also reject wide string literals.
if (StringLiteral *MessageStringLiteral =
cast_or_null<StringLiteral>(MessageExpr.get())) {
if (MessageStringLiteral->getCharByteWidth() != 1) {
Diag(MessageStringLiteral->getSourceRange().getBegin(),
diag::err_expected_string_literal)
<< /*Source='availability attribute'*/ 2;
SkipUntil(tok::r_paren, StopAtSemi);
return;
}
}
break;
}

View File

@ -20,6 +20,8 @@ void f6() __attribute__((availability(macosx,unavailable,introduced=10.5))); //
void f7() __attribute__((availability(macosx,message=L"wide"))); // expected-error {{expected string literal for optional message in 'availability' attribute}}
void f8() __attribute__((availability(macosx,message="a" L"b"))); // expected-error {{expected string literal for optional message in 'availability' attribute}}
// rdar://10095131
enum E{
gorf __attribute__((availability(macosx,introduced=8.5, message = 10.0))), // expected-error {{expected string literal for optional message in 'availability' attribute}}