]> granicus.if.org Git - clang/commitdiff
As Aaron pointed out it's simpler to reject wide string availability attr messages...
authorBenjamin Kramer <benny.kra@googlemail.com>
Fri, 13 Sep 2013 17:31:48 +0000 (17:31 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Fri, 13 Sep 2013 17:31:48 +0000 (17:31 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190706 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseDecl.cpp
lib/Sema/SemaDeclAttr.cpp
test/Parser/attr-availability.c
test/Sema/attr-availability.c

index 74982a3894e89032faf9432491810d24a355c380..915fb607a68d43de15552e3cb1c1e8355807e7a5 100644 (file)
@@ -885,7 +885,7 @@ void Parser::ParseAvailabilityAttribute(IdentifierInfo &Availability,
     }
     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);
index 8d01d638d385015dcd8c453d706f56905d70d79d..8530c8bd158aa3c118ee0eda975bd951fbdbbe21 100644 (file)
@@ -2267,16 +2267,9 @@ static void handleAvailabilityAttr(Sema &S, Decl *D,
   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,
index 0ed8391775310cda25579f6a4a7ca14789dae2ce..06bebbad5c59ae227b1478454515255d604de593 100644 (file)
@@ -18,6 +18,8 @@ void f5() __attribute__((availability(macosx,introduced=10.5), availability(ios,
 
 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}}
index f7bd74d8d3bc6d9b7a29bf6759af53d899a1f4c6..ac6a187591b07be1e8f9b8d1f5bb99a6cc46f4e6 100644 (file)
@@ -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}}