[cfe-commits] r38677 - in /cfe/cfe/trunk: Lex/Preprocessor.cpp clang.xcodeproj/project.pbxproj include/clang/Basic/DiagnosticKinds.def

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


Author: sabre
Date: Wed Jul 11 11:23:44 2007
New Revision: 38677

URL: http://llvm.org/viewvc/llvm-project?rev=38677&view=rev
Log:
Diagnose erroneous macro definitions where a ## operator is at the start/end of the macro

Modified:
    cfe/cfe/trunk/Lex/Preprocessor.cpp
    cfe/cfe/trunk/clang.xcodeproj/project.pbxproj
    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=38677&r1=38676&r2=38677&view=diff

==============================================================================
--- cfe/cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/cfe/trunk/Lex/Preprocessor.cpp Wed Jul 11 11:23:44 2007
@@ -1330,6 +1330,7 @@
   } else if (Tok.getKind() == tok::l_paren && !Tok.hasLeadingSpace()) {
     // This is a function-like macro definition.
     //assert(0 && "Function-like macros not implemented!");
+    delete MI;
     return DiscardUntilEndOfDirective();
 
   } else if (!Tok.hasLeadingSpace()) {
@@ -1351,11 +1352,30 @@
   while (Tok.getKind() != tok::eom) {
     MI->AddTokenToBody(Tok);
     
-    // FIXME: Read macro body.  See create_iso_definition.
-    
+    // FIXME: Check for #'s that aren't followed by argument names.
+    // See create_iso_definition.
+
     // Get the next token of the macro.
     LexUnexpandedToken(Tok);
   }
+
+  unsigned NumTokens = MI->getNumTokens();
+
+  // Check that there is no paste (##) operator at the begining or end of the
+  // replacement list.
+  if (NumTokens != 0) {
+    if (MI->getReplacementToken(0).getKind() == tok::hashhash) {
+      SourceLocation Loc = MI->getReplacementToken(0).getLocation();
+      delete MI;
+      return Diag(Loc, diag::err_paste_at_start);
+    }
+    if (MI->getReplacementToken(NumTokens-1).getKind() == tok::hashhash) {
+      SourceLocation Loc = MI->getReplacementToken(NumTokens-1).getLocation();
+      delete MI;
+      return Diag(Loc, diag::err_paste_at_end);
+    }
+  }
+  
   
   // If this is the primary source file, remember that this macro hasn't been
   // used yet.

Modified: cfe/cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=38677&r1=38676&r2=38677&view=diff

==============================================================================
--- cfe/cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/cfe/trunk/clang.xcodeproj/project.pbxproj Wed Jul 11 11:23:44 2007
@@ -92,7 +92,7 @@
 /* End PBXCopyFilesBuildPhase section */
 
 /* Begin PBXFileReference section */
-		8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
+		8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
 		DEAEE98A0A5A2B970045101B /* MultipleIncludeOpt.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = MultipleIncludeOpt.h; sourceTree = "<group>"; };
 		DEAEECAC0A5AF0E30045101B /* clang.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = clang.h; sourceTree = "<group>"; };
 		DEAEECD40A5AF1FE0045101B /* PrintPreprocessedOutput.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = PrintPreprocessedOutput.cpp; sourceTree = "<group>"; };

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=38677&r1=38676&r2=38677&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def Wed Jul 11 11:23:44 2007
@@ -181,6 +181,10 @@
      "_Pragma takes a parenthesized string literal")
 DIAG(err_defined_macro_name, ERROR,
      "\"defined\" cannot be used as a macro name")
+DIAG(err_paste_at_start, ERROR,
+     "\"##\" cannot appear at start of macro expansion")
+DIAG(err_paste_at_end, ERROR,
+     "\"##\" cannot appear at end of macro expansion")
 
 // Should be a sorry?
 DIAG(err_pp_I_dash_not_supported, ERROR,





More information about the cfe-commits mailing list