From: Chris Lattner Date: Thu, 19 Jul 2007 16:11:58 +0000 (+0000) Subject: Fix a stringizing bug that Neil noticed. We should preprocess this: X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2b64fdc4993795af86fd79f02085268e7be0dc4d;p=clang Fix a stringizing bug that Neil noticed. We should preprocess this: #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 --- diff --git a/Lex/MacroExpander.cpp b/Lex/MacroExpander.cpp index ed1725dccf..e474906050 100644 --- a/Lex/MacroExpander.cpp +++ b/Lex/MacroExpander.cpp @@ -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; diff --git a/Lex/Preprocessor.cpp b/Lex/Preprocessor.cpp index bc7ad12e56..7b6c57186c 100644 --- a/Lex/Preprocessor.cpp +++ b/Lex/Preprocessor.cpp @@ -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 index 0000000000..cf81674065 --- /dev/null +++ b/test/Preprocessor/stringize_space2.c @@ -0,0 +1,6 @@ +/* RUN: clang -E %s | grep 'a c' + */ +#define t(x) #x +t(a +c) +