[cfe-commits] r40060 - in /cfe/trunk: Lex/MacroExpander.cpp Lex/Preprocessor.cpp test/Preprocessor/stringize_space2.c

Chris Lattner sabre at nondot.org
Thu Jul 19 09:11:59 PDT 2007


Author: lattner
Date: Thu Jul 19 11:11:58 2007
New Revision: 40060

URL: http://llvm.org/viewvc/llvm-project?rev=40060&view=rev
Log:
Fix a stringizing bug that Neil noticed.  We should preprocess this:
#define t(x) #x
t(a
c)

to "a c", not "ac".


Added:
    cfe/trunk/test/Preprocessor/stringize_space2.c
Modified:
    cfe/trunk/Lex/MacroExpander.cpp
    cfe/trunk/Lex/Preprocessor.cpp

Modified: cfe/trunk/Lex/MacroExpander.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Lex/MacroExpander.cpp?rev=40060&r1=40059&r2=40060&view=diff

==============================================================================
--- cfe/trunk/Lex/MacroExpander.cpp (original)
+++ cfe/trunk/Lex/MacroExpander.cpp Thu Jul 19 11:11:58 2007
@@ -153,7 +153,7 @@
   bool isFirst = true;
   for (; ArgToks->getKind() != tok::eof; ++ArgToks) {
     const LexerToken &Tok = *ArgToks;
-    if (!isFirst && Tok.hasLeadingSpace())
+    if (!isFirst && (Tok.hasLeadingSpace() || Tok.isAtStartOfLine()))
       Result += ' ';
     isFirst = false;
     

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

==============================================================================
--- cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/Lex/Preprocessor.cpp Thu Jul 19 11:11:58 2007
@@ -613,7 +613,8 @@
   // If this is a function-like macro, read the arguments.
   if (MI->isFunctionLike()) {
     // C99 6.10.3p10: If the preprocessing token immediately after the the macro
-    // name isn't a '(', this macro should not be expanded.
+    // name isn't a '(', this macro should not be expanded.  Otherwise, consume
+    // it.
     if (!isNextPPTokenLParen())
       return true;
     
@@ -731,7 +732,8 @@
 
   unsigned NumActuals = 0;
   while (Tok.getKind() == tok::comma) {
-    // C99 6.10.3p11: Keep track of the number of l_parens we have seen.
+    // C99 6.10.3p11: Keep track of the number of l_parens we have seen.  Note
+    // that we already consumed the first one.
     unsigned NumParens = 0;
     
     while (1) {

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

==============================================================================
--- cfe/trunk/test/Preprocessor/stringize_space2.c (added)
+++ cfe/trunk/test/Preprocessor/stringize_space2.c Thu Jul 19 11:11:58 2007
@@ -0,0 +1,6 @@
+/* RUN: clang -E %s | grep 'a c'
+ */
+#define t(x) #x
+t(a
+c)
+





More information about the cfe-commits mailing list