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

David Majnemer david.majnemer at gmail.com
Thu Jul 17 22:43:13 PDT 2014


Author: majnemer
Date: Fri Jul 18 00:43:12 2014
New Revision: 213350

URL: http://llvm.org/viewvc/llvm-project?rev=213350&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/Parse/ParseDecl.cpp
    cfe/trunk/test/Parser/attr-availability.c

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=213350&r1=213349&r2=213350&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Fri Jul 18 00:43:12 2014
@@ -825,13 +825,24 @@ void Parser::ParseAvailabilityAttribute(
     }
     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;
     }
 

Modified: cfe/trunk/test/Parser/attr-availability.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/attr-availability.c?rev=213350&r1=213349&r2=213350&view=diff
==============================================================================
--- cfe/trunk/test/Parser/attr-availability.c (original)
+++ cfe/trunk/test/Parser/attr-availability.c Fri Jul 18 00:43:12 2014
@@ -20,6 +20,8 @@ void f6() __attribute__((availability(ma
 
 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}}





More information about the cfe-commits mailing list