r190706 - As Aaron pointed out it's simpler to reject wide string availability attr messages in the parser.
Benjamin Kramer
benny.kra at googlemail.com
Fri Sep 13 10:31:48 PDT 2013
Author: d0k
Date: Fri Sep 13 12:31:48 2013
New Revision: 190706
URL: http://llvm.org/viewvc/llvm-project?rev=190706&view=rev
Log:
As Aaron pointed out it's simpler to reject wide string availability attr messages in the parser.
Modified:
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/Parser/attr-availability.c
cfe/trunk/test/Sema/attr-availability.c
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=190706&r1=190705&r2=190706&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Fri Sep 13 12:31:48 2013
@@ -885,7 +885,7 @@ void Parser::ParseAvailabilityAttribute(
}
ConsumeToken();
if (Keyword == Ident_message) {
- if (!isTokenStringLiteral()) {
+ if (Tok.isNot(tok::string_literal)) { // Also reject wide string literals.
Diag(Tok, diag::err_expected_string_literal)
<< /*Source='availability attribute'*/2;
SkipUntil(tok::r_paren);
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=190706&r1=190705&r2=190706&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri Sep 13 12:31:48 2013
@@ -2267,16 +2267,9 @@ static void handleAvailabilityAttr(Sema
AvailabilityChange Obsoleted = Attr.getAvailabilityObsoleted();
bool IsUnavailable = Attr.getUnavailableLoc().isValid();
StringRef Str;
- if (Attr.getMessageExpr()) {
- const StringLiteral *SE = dyn_cast<StringLiteral>(Attr.getMessageExpr());
- if (!SE || !SE->isAscii()) {
- S.Diag(Attr.getMessageExpr()->getLocStart(),
- diag::err_attribute_argument_type)
- << Attr.getName() << AANT_ArgumentString;
- return;
- }
+ if (const StringLiteral *SE =
+ dyn_cast_or_null<StringLiteral>(Attr.getMessageExpr()))
Str = SE->getString();
- }
AvailabilityAttr *NewAttr = S.mergeAvailabilityAttr(ND, Attr.getRange(), II,
Introduced.Version,
Modified: cfe/trunk/test/Parser/attr-availability.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/attr-availability.c?rev=190706&r1=190705&r2=190706&view=diff
==============================================================================
--- cfe/trunk/test/Parser/attr-availability.c (original)
+++ cfe/trunk/test/Parser/attr-availability.c Fri Sep 13 12:31:48 2013
@@ -18,6 +18,8 @@ void f5() __attribute__((availability(ma
void f6() __attribute__((availability(macosx,unavailable,introduced=10.5))); // expected-warning{{'unavailable' availability overrides all other availability information}}
+void f7() __attribute__((availability(macosx,message=L"wide"))); // 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}}
Modified: cfe/trunk/test/Sema/attr-availability.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-availability.c?rev=190706&r1=190705&r2=190706&view=diff
==============================================================================
--- cfe/trunk/test/Sema/attr-availability.c (original)
+++ cfe/trunk/test/Sema/attr-availability.c Fri Sep 13 12:31:48 2013
@@ -54,5 +54,3 @@ void f8() {
extern int x2 __attribute__((availability(macosx,introduced=10.2))); // expected-note {{previous attribute is here}}
extern int x2 __attribute__((availability(macosx,introduced=10.5))); // expected-warning {{availability does not match previous declaration}}
-
-extern int x3 __attribute__((availability(macosx,message=L"wide"))); // expected-error {{'availability' attribute requires a string}}
More information about the cfe-commits
mailing list