]> granicus.if.org Git - clang/commitdiff
Fix a stringizing bug that Neil noticed. We should preprocess this:
authorChris Lattner <sabre@nondot.org>
Thu, 19 Jul 2007 16:11:58 +0000 (16:11 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 19 Jul 2007 16:11:58 +0000 (16:11 +0000)
#define t(x) #x
t(a
c)

to "a c", not "ac".

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40060 91177308-0d34-0410-b5e6-96231b3b80d8

Lex/MacroExpander.cpp
Lex/Preprocessor.cpp
test/Preprocessor/stringize_space2.c [new file with mode: 0644]

index ed1725dccf7959dc0eab78012b46b22ab30b5af3..e474906050ba7cd0a2bc30529f3923329b396206 100644 (file)
@@ -153,7 +153,7 @@ static LexerToken StringifyArgument(const LexerToken *ArgToks,
   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;
     
index bc7ad12e5647ea67ee80fd33ac2e086d73fee59f..7b6c57186cbc493fe96817d41b30f6dc666c0df5 100644 (file)
@@ -613,7 +613,8 @@ bool Preprocessor::HandleMacroExpandedIdentifier(LexerToken &Identifier,
   // 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 @@ MacroArgs *Preprocessor::ReadFunctionLikeMacroArgs(LexerToken &MacroName,
 
   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) {
diff --git a/test/Preprocessor/stringize_space2.c b/test/Preprocessor/stringize_space2.c
new file mode 100644 (file)
index 0000000..cf81674
--- /dev/null
@@ -0,0 +1,6 @@
+/* RUN: clang -E %s | grep 'a c'
+ */
+#define t(x) #x
+t(a
+c)
+