[cfe-commits] r168267 - in /cfe/trunk: include/clang/Basic/DiagnosticCommonKinds.td include/clang/Lex/Preprocessor.h lib/Lex/PPMacroExpansion.cpp lib/Lex/Pragma.cpp lib/Lex/Preprocessor.cpp lib/Parse/ParseDecl.cpp lib/Parse/ParseDeclCXX.cpp lib/Parse/Parser.cpp test/Lexer/pragma-message.c test/Parser/attr-availability.c test/Preprocessor/pragma_diagnostic.c test/Preprocessor/pragma_microsoft.c test/Preprocessor/warning_tests.c test/Sema/static-assert.c

Andy Gibbs andyg1001 at hotmail.co.uk
Sat Nov 17 11:16:53 PST 2012


Author: andyg
Date: Sat Nov 17 13:16:52 2012
New Revision: 168267

URL: http://llvm.org/viewvc/llvm-project?rev=168267&view=rev
Log:
Made the "expected string literal" diagnostic more expressive

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
    cfe/trunk/include/clang/Lex/Preprocessor.h
    cfe/trunk/lib/Lex/PPMacroExpansion.cpp
    cfe/trunk/lib/Lex/Pragma.cpp
    cfe/trunk/lib/Lex/Preprocessor.cpp
    cfe/trunk/lib/Parse/ParseDecl.cpp
    cfe/trunk/lib/Parse/ParseDeclCXX.cpp
    cfe/trunk/lib/Parse/Parser.cpp
    cfe/trunk/test/Lexer/pragma-message.c
    cfe/trunk/test/Parser/attr-availability.c
    cfe/trunk/test/Preprocessor/pragma_diagnostic.c
    cfe/trunk/test/Preprocessor/pragma_microsoft.c
    cfe/trunk/test/Preprocessor/warning_tests.c
    cfe/trunk/test/Sema/static-assert.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td?rev=168267&r1=168266&r2=168267&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td Sat Nov 17 13:16:52 2012
@@ -41,7 +41,9 @@
 def err_expected_colon_after_setter_name : Error<
   "method name referenced in property setter attribute "
   "must end with ':'">;
-def err_expected_string_literal : Error<"expected string literal">;
+def err_expected_string_literal : Error<"expected string literal "
+  "%select{in %1|for diagnostic message in static_assert|"
+          "for optional message in 'availability' attribute}0">;
 def err_invalid_string_udl : Error<
   "string literal with user-defined suffix cannot be used here">;
 def err_invalid_character_udl : Error<

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=168267&r1=168266&r2=168267&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Sat Nov 17 13:16:52 2012
@@ -700,17 +700,19 @@
   /// string literals and may even come from macro expansion.
   /// \returns true on success, false if a error diagnostic has been generated.
   bool LexStringLiteral(Token &Result, std::string &String,
-                        bool AllowMacroExpansion) {
+                        const char *DiagnosticTag, bool AllowMacroExpansion) {
     if (AllowMacroExpansion)
       Lex(Result);
     else
       LexUnexpandedToken(Result);
-    return FinishLexStringLiteral(Result, String, AllowMacroExpansion);
+    return FinishLexStringLiteral(Result, String, DiagnosticTag,
+                                  AllowMacroExpansion);
   }
 
   /// \brief Complete the lexing of a string literal where the first token has
   /// already been lexed (see LexStringLiteral).
   bool FinishLexStringLiteral(Token &Result, std::string &String,
+                              const char *DiagnosticTag,
                               bool AllowMacroExpansion);
 
   /// LexNonComment - Lex a token.  If it's a comment, keep lexing until we get

Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=168267&r1=168266&r2=168267&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Sat Nov 17 13:16:52 2012
@@ -1290,7 +1290,8 @@
       LexUnexpandedToken(Tok);
       std::string WarningName;
       SourceLocation StrStartLoc = Tok.getLocation();
-      if (!FinishLexStringLiteral(Tok, WarningName, /*MacroExpansion=*/false)) {
+      if (!FinishLexStringLiteral(Tok, WarningName, "'__has_warning'",
+                                  /*MacroExpansion=*/false)) {
         // Eat tokens until ')'.
         while (Tok.isNot(tok::r_paren)
                  && Tok.isNot(tok::eod)

Modified: cfe/trunk/lib/Lex/Pragma.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Pragma.cpp?rev=168267&r1=168266&r2=168267&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Pragma.cpp (original)
+++ cfe/trunk/lib/Lex/Pragma.cpp Sat Nov 17 13:16:52 2012
@@ -503,6 +503,7 @@
   Lex(Tok);
   std::string ArgumentString;
   if (Tok.is(tok::comma) && !LexStringLiteral(Tok, ArgumentString,
+                                              "pragma comment",
                                               /*MacroExpansion=*/true))
     return;
 
@@ -559,7 +560,8 @@
   }
 
   std::string MessageString;
-  if (!FinishLexStringLiteral(Tok, MessageString, /*MacroExpansion=*/true))
+  if (!FinishLexStringLiteral(Tok, MessageString, "pragma message",
+                              /*MacroExpansion=*/true))
     return;
 
   if (ExpectClosingParen) {
@@ -1039,7 +1041,8 @@
     SourceLocation StringLoc = Tok.getLocation();
 
     std::string WarningName;
-    if (!PP.FinishLexStringLiteral(Tok, WarningName, /*MacroExpansion=*/false))
+    if (!PP.FinishLexStringLiteral(Tok, WarningName, "pragma diagnostic",
+                                   /*MacroExpansion=*/false))
       return;
 
     if (Tok.isNot(tok::eod)) {

Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=168267&r1=168266&r2=168267&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Sat Nov 17 13:16:52 2012
@@ -691,10 +691,12 @@
 }
 
 bool Preprocessor::FinishLexStringLiteral(Token &Result, std::string &String,
+                                          const char *DiagnosticTag,
                                           bool AllowMacroExpansion) {
   // We need at least one string literal.
   if (Result.isNot(tok::string_literal)) {
-    Diag(Result, diag::err_expected_string_literal);
+    Diag(Result, diag::err_expected_string_literal)
+      << /*Source='in...'*/0 << DiagnosticTag;
     return false;
   }
 
@@ -720,7 +722,8 @@
     return false;
 
   if (Literal.Pascal) {
-    Diag(StrToks[0].getLocation(), diag::err_expected_string_literal);
+    Diag(StrToks[0].getLocation(), diag::err_expected_string_literal)
+      << /*Source='in...'*/0 << DiagnosticTag;
     return false;
   }
 

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=168267&r1=168266&r2=168267&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Sat Nov 17 13:16:52 2012
@@ -735,7 +735,8 @@
     ConsumeToken();
     if (Keyword == Ident_message) {
       if (!isTokenStringLiteral()) {
-        Diag(Tok, diag::err_expected_string_literal);
+        Diag(Tok, diag::err_expected_string_literal)
+          << /*Source='availability attribute'*/2;
         SkipUntil(tok::r_paren);
         return;
       }

Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=168267&r1=168266&r2=168267&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Sat Nov 17 13:16:52 2012
@@ -637,7 +637,8 @@
     return 0;
 
   if (!isTokenStringLiteral()) {
-    Diag(Tok, diag::err_expected_string_literal);
+    Diag(Tok, diag::err_expected_string_literal)
+      << /*Source='static_assert'*/1;
     SkipMalformedDecl();
     return 0;
   }

Modified: cfe/trunk/lib/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=168267&r1=168266&r2=168267&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Sat Nov 17 13:16:52 2012
@@ -1263,7 +1263,8 @@
       return ExprError();
     }
     default:
-      Diag(Tok, diag::err_expected_string_literal);
+      Diag(Tok, diag::err_expected_string_literal)
+        << /*Source='in...'*/0 << "'asm'";
       return ExprError();
   }
 

Modified: cfe/trunk/test/Lexer/pragma-message.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/pragma-message.c?rev=168267&r1=168266&r2=168267&view=diff
==============================================================================
--- cfe/trunk/test/Lexer/pragma-message.c (original)
+++ cfe/trunk/test/Lexer/pragma-message.c Sat Nov 17 13:16:52 2012
@@ -12,3 +12,5 @@
 #define STRING(x) STRING2(x)
 #pragma message(":O I'm a message! " STRING(__LINE__)) // expected-warning {{:O I'm a message! 13}}
 #pragma message ":O gcc accepts this! " STRING(__LINE__) // expected-warning {{:O gcc accepts this! 14}}
+
+#pragma message(invalid) // expected-error {{expected string literal in pragma message}}

Modified: cfe/trunk/test/Parser/attr-availability.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/attr-availability.c?rev=168267&r1=168266&r2=168267&view=diff
==============================================================================
--- cfe/trunk/test/Parser/attr-availability.c (original)
+++ cfe/trunk/test/Parser/attr-availability.c Sat Nov 17 13:16:52 2012
@@ -20,7 +20,7 @@
 
 // rdar://10095131
 enum E{
-    gorf __attribute__((availability(macosx,introduced=8.5, message = 10.0))), // expected-error {{expected string literal}}
+    gorf __attribute__((availability(macosx,introduced=8.5, message = 10.0))), // expected-error {{expected string literal for optional message in 'availability' attribute}}
     garf __attribute__((availability(macosx,introduced=8.5, message))), // expected-error {{expected '=' after 'message'}}
 
     foo __attribute__((availability(macosx,introduced=8.5,deprecated=9.0, message="Use CTFontCopyPostScriptName()", deprecated=10.0))) // expected-error {{expected ')'}} \

Modified: cfe/trunk/test/Preprocessor/pragma_diagnostic.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/pragma_diagnostic.c?rev=168267&r1=168266&r2=168267&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/pragma_diagnostic.c (original)
+++ cfe/trunk/test/Preprocessor/pragma_diagnostic.c Sat Nov 17 13:16:52 2012
@@ -23,7 +23,7 @@
 #define foo error
 #pragma GCC diagnostic foo "-Wundef"  // expected-warning {{pragma diagnostic expected 'error', 'warning', 'ignored', 'fatal', 'push', or 'pop'}}
 
-#pragma GCC diagnostic error 42  // expected-error {{expected string literal}}
+#pragma GCC diagnostic error 42  // expected-error {{expected string literal in pragma diagnostic}}
 
 #pragma GCC diagnostic error "-Wundef" 42  // expected-warning {{unexpected token in pragma diagnostic}}
 #pragma GCC diagnostic error "invalid-name"  // expected-warning {{pragma diagnostic expected option name (e.g. "-Wundef")}}

Modified: cfe/trunk/test/Preprocessor/pragma_microsoft.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/pragma_microsoft.c?rev=168267&r1=168266&r2=168267&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/pragma_microsoft.c (original)
+++ cfe/trunk/test/Preprocessor/pragma_microsoft.c Sat Nov 17 13:16:52 2012
@@ -11,7 +11,7 @@
 #pragma comment( user, "Compiled on " __DATE__ " at " __TIME__ ) 
 
 #pragma comment(foo)    // expected-error {{unknown kind of pragma comment}}
-#pragma comment(compiler,)     // expected-error {{expected string literal}}
+#pragma comment(compiler,)     // expected-error {{expected string literal in pragma comment}}
 #define foo compiler
 #pragma comment(foo)   // macro expand kind.
 #pragma comment(foo) x // expected-error {{pragma comment requires}}

Modified: cfe/trunk/test/Preprocessor/warning_tests.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/warning_tests.c?rev=168267&r1=168266&r2=168267&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/warning_tests.c (original)
+++ cfe/trunk/test/Preprocessor/warning_tests.c Sat Nov 17 13:16:52 2012
@@ -11,7 +11,7 @@
 #warning Should have -Wparentheses
 #endif
 
-// expected-error at +2 {{expected string literal}}
+// expected-error at +2 {{expected string literal in '__has_warning'}}
 // expected-error at +1 {{expected value in expression}}
 #if __has_warning(-Wfoo)
 #endif

Modified: cfe/trunk/test/Sema/static-assert.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/static-assert.c?rev=168267&r1=168266&r2=168267&view=diff
==============================================================================
--- cfe/trunk/test/Sema/static-assert.c (original)
+++ cfe/trunk/test/Sema/static-assert.c Sat Nov 17 13:16:52 2012
@@ -9,3 +9,5 @@
   _Static_assert(1, "1 is nonzero");
   _Static_assert(0, "0 is nonzero"); // expected-error {{static_assert failed "0 is nonzero"}}
 }
+
+_Static_assert(1, invalid); // expected-error {{expected string literal for diagnostic message in static_assert}}





More information about the cfe-commits mailing list