[cfe-commits] r38683 - in /cfe/cfe/trunk: Lex/Preprocessor.cpp include/clang/Basic/DiagnosticKinds.def

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:23:48 PDT 2007


Author: sabre
Date: Wed Jul 11 11:23:48 2007
New Revision: 38683

URL: http://llvm.org/viewvc/llvm-project?rev=38683&view=rev
Log:
Diagnose C99 6.10.3.2p1

Modified:
    cfe/cfe/trunk/Lex/Preprocessor.cpp
    cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def

Modified: cfe/cfe/trunk/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/Preprocessor.cpp?rev=38683&r1=38682&r2=38683&view=diff

==============================================================================
--- cfe/cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/cfe/trunk/Lex/Preprocessor.cpp Wed Jul 11 11:23:48 2007
@@ -1455,6 +1455,8 @@
       return;
     }
 
+    // Read the first token after the arg list for down below.
+    LexUnexpandedToken(Tok);
   } else if (!Tok.hasLeadingSpace()) {
     // C99 requires whitespace between the macro definition and the body.  Emit
     // a diagnostic for something like "#define X+".
@@ -1473,9 +1475,29 @@
   // Read the rest of the macro body.
   while (Tok.getKind() != tok::eom) {
     MI->AddTokenToBody(Tok);
+
+    // Check C99 6.10.3.2p1: ensure that # operators are followed by macro
+    // parameters.
+    if (Tok.getKind() != tok::hash) {
+      // Get the next token of the macro.
+      LexUnexpandedToken(Tok);
+      continue;
+    }
     
-    // FIXME: Check for #'s that aren't followed by argument names.
-    // See create_iso_definition.
+    // Get the next token of the macro.
+    LexUnexpandedToken(Tok);
+   
+    // Not a macro arg identifier?
+    if (!Tok.getIdentifierInfo() || !Tok.getIdentifierInfo()->isMacroArg()) {
+      Diag(Tok, diag::err_pp_stringize_not_parameter);
+      // Clear the "isMacroArg" flags from all the macro arguments.
+      MI->SetIdentifierIsMacroArgFlags(false);
+      delete MI;
+      return;
+    }
+    
+    // Things look ok, add the param name token to the macro.
+    MI->AddTokenToBody(Tok);
 
     // Get the next token of the macro.
     LexUnexpandedToken(Tok);
@@ -1487,22 +1509,21 @@
   // replacement list.
   if (NumTokens != 0) {
     if (MI->getReplacementToken(0).getKind() == tok::hashhash) {
-      SourceLocation Loc = MI->getReplacementToken(0).getLocation();
+      Diag(MI->getReplacementToken(0), diag::err_paste_at_start);
       // Clear the "isMacroArg" flags from all the macro arguments.
       MI->SetIdentifierIsMacroArgFlags(false);
       delete MI;
-      return Diag(Loc, diag::err_paste_at_start);
+      return;
     }
     if (MI->getReplacementToken(NumTokens-1).getKind() == tok::hashhash) {
-      SourceLocation Loc = MI->getReplacementToken(NumTokens-1).getLocation();
+      Diag(MI->getReplacementToken(NumTokens-1), diag::err_paste_at_end);
       // Clear the "isMacroArg" flags from all the macro arguments.
       MI->SetIdentifierIsMacroArgFlags(false);
       delete MI;
-      return Diag(Loc, diag::err_paste_at_end);
+      return;
     }
   }
   
-  
   // If this is the primary source file, remember that this macro hasn't been
   // used yet.
   if (isInPrimaryFile())

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

==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def Wed Jul 11 11:23:48 2007
@@ -157,6 +157,8 @@
      "expected comma in macro parameter list")
 DIAG(err_pp_duplicate_name_in_arg_list, ERROR,
      "duplicate macro parameter name \"%s\"")
+DIAG(err_pp_stringize_not_parameter, ERROR,
+     "'#' is not followed by a macro parameter")
 DIAG(err_pp_malformed_ident, ERROR,
      "invalid #ident directive")
 DIAG(err_pp_unterminated_conditional, ERROR,





More information about the cfe-commits mailing list