forked from OSchip/llvm-project
Fix inconsistent availability attribute message string literal check.
Function Parser::ParseAvailabilityAttribute checks that the message string of an availability attribute is not a wide string literal. Test case clang/test/Parser/attr-availability.c specifies that a string literal is expected. The code checked that the first token in a string concatenation is a string literal, and then that the concatenated string consists of 1-byte characters. On a target where wide character is 1 byte, a string concatenation "a" L"b" passes both those checks, but L"b" alone is rejected. More generally, "a" u8"b" passes the checks, but u8"b" alone is rejected. So check isAscii() instead of character size.
This commit is contained in:
parent
09f2f9605f
commit
27ea7d0a6e
|
@ -1119,7 +1119,7 @@ void Parser::ParseAvailabilityAttribute(IdentifierInfo &Availability,
|
|||
// Also reject wide string literals.
|
||||
if (StringLiteral *MessageStringLiteral =
|
||||
cast_or_null<StringLiteral>(MessageExpr.get())) {
|
||||
if (MessageStringLiteral->getCharByteWidth() != 1) {
|
||||
if (!MessageStringLiteral->isAscii()) {
|
||||
Diag(MessageStringLiteral->getSourceRange().getBegin(),
|
||||
diag::err_expected_string_literal)
|
||||
<< /*Source='availability attribute'*/ 2;
|
||||
|
|
|
@ -22,6 +22,14 @@ void f7() __attribute__((availability(macosx,message=L"wide"))); // expected-err
|
|||
|
||||
void f8() __attribute__((availability(macosx,message="a" L"b"))); // expected-error {{expected string literal for optional message in 'availability' attribute}}
|
||||
|
||||
void f9() __attribute__((availability(macosx,message=u8"b"))); // expected-error {{expected string literal for optional message in 'availability' attribute}}
|
||||
|
||||
void f10() __attribute__((availability(macosx,message="a" u8"b"))); // expected-error {{expected string literal for optional message in 'availability' attribute}}
|
||||
|
||||
void f11() __attribute__((availability(macosx,message=u"b"))); // expected-error {{expected string literal for optional message in 'availability' attribute}}
|
||||
|
||||
void f12() __attribute__((availability(macosx,message="a" u"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}}
|
||||
|
|
Loading…
Reference in New Issue