[cfe-commits] r49619 - in /cfe/trunk: include/clang/Basic/DiagnosticKinds.def lib/Lex/PPExpressions.cpp test/Preprocessor/expr_invalid_tok.c

Chris Lattner sabre at nondot.org
Sun Apr 13 13:38:44 PDT 2008


Author: lattner
Date: Sun Apr 13 15:38:43 2008
New Revision: 49619

URL: http://llvm.org/viewvc/llvm-project?rev=49619&view=rev
Log:
Fix PR2220, making diagnostics for unexpected tokens in pp expressions 
more nice.

Added:
    cfe/trunk/test/Preprocessor/expr_invalid_tok.c
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticKinds.def
    cfe/trunk/lib/Lex/PPExpressions.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=49619&r1=49618&r2=49619&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Sun Apr 13 15:38:43 2008
@@ -207,8 +207,10 @@
      "division by zero in preprocessor expression")
 DIAG(err_pp_remainder_by_zero, ERROR,
      "remainder by zero in preprocessor expression")
-DIAG(err_pp_expr_bad_token, ERROR,
-     "token is not valid in preprocessor expressions")
+DIAG(err_pp_expr_bad_token_binop, ERROR,
+     "token is not a valid binary operator in a preprocessor subexpression")
+DIAG(err_pp_expr_bad_token_start_expr, ERROR,
+     "invalid token at start of a preprocessor expression")
 DIAG(err_pp_invalid_poison, ERROR,
      "can only poison identifier tokens")
 DIAG(err_pp_used_poisoned_id, ERROR,

Modified: cfe/trunk/lib/Lex/PPExpressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPExpressions.cpp?rev=49619&r1=49618&r2=49619&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/PPExpressions.cpp (original)
+++ cfe/trunk/lib/Lex/PPExpressions.cpp Sun Apr 13 15:38:43 2008
@@ -131,7 +131,7 @@
   
   switch (PeekTok.getKind()) {
   default:  // Non-value token.
-    PP.Diag(PeekTok, diag::err_pp_expr_bad_token);
+    PP.Diag(PeekTok, diag::err_pp_expr_bad_token_start_expr);
     return true;
   case tok::eom:
   case tok::r_paren:
@@ -349,7 +349,7 @@
   unsigned PeekPrec = getPrecedence(PeekTok.getKind());
   // If this token isn't valid, report the error.
   if (PeekPrec == ~0U) {
-    PP.Diag(PeekTok, diag::err_pp_expr_bad_token);
+    PP.Diag(PeekTok, diag::err_pp_expr_bad_token_binop);
     return true;
   }
   
@@ -392,7 +392,7 @@
 
     // If this token isn't valid, report the error.
     if (PeekPrec == ~0U) {
-      PP.Diag(PeekTok, diag::err_pp_expr_bad_token);
+      PP.Diag(PeekTok, diag::err_pp_expr_bad_token_binop);
       return true;
     }
     

Added: cfe/trunk/test/Preprocessor/expr_invalid_tok.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/expr_invalid_tok.c?rev=49619&view=auto

==============================================================================
--- cfe/trunk/test/Preprocessor/expr_invalid_tok.c (added)
+++ cfe/trunk/test/Preprocessor/expr_invalid_tok.c Sun Apr 13 15:38:43 2008
@@ -0,0 +1,10 @@
+// RUN: not clang -E %s 2>&1 | grep 'invalid token at start of a preprocessor expression'
+// RUN: not clang -E %s 2>&1 | grep 'token is not a valid binary operator in a preprocessor subexpression'
+// PR2220
+
+#if 1 * * 2
+#endif
+
+#if 4 [ 2
+#endif
+





More information about the cfe-commits mailing list