summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-07-19 16:11:58 +0000
committerChris Lattner <sabre@nondot.org>2007-07-19 16:11:58 +0000
commit24dbee71abad508f4f19195d7d373b10bc792fac (patch)
tree3e9b0e1ff674b7455c74ba88494b81c60918df04
parentb4acc033cf9e11b75f0cbf103332415461dcad96 (diff)
downloadbcm5719-llvm-24dbee71abad508f4f19195d7d373b10bc792fac.tar.gz
bcm5719-llvm-24dbee71abad508f4f19195d7d373b10bc792fac.zip
Fix a stringizing bug that Neil noticed. We should preprocess this:
#define t(x) #x t(a c) to "a c", not "ac". llvm-svn: 40060
-rw-r--r--clang/Lex/MacroExpander.cpp2
-rw-r--r--clang/Lex/Preprocessor.cpp6
-rw-r--r--clang/test/Preprocessor/stringize_space2.c6
3 files changed, 11 insertions, 3 deletions
diff --git a/clang/Lex/MacroExpander.cpp b/clang/Lex/MacroExpander.cpp
index ed1725dccf7..e474906050b 100644
--- a/clang/Lex/MacroExpander.cpp
+++ b/clang/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/clang/Lex/Preprocessor.cpp b/clang/Lex/Preprocessor.cpp
index bc7ad12e564..7b6c57186cb 100644
--- a/clang/Lex/Preprocessor.cpp
+++ b/clang/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/clang/test/Preprocessor/stringize_space2.c b/clang/test/Preprocessor/stringize_space2.c
new file mode 100644
index 00000000000..cf81674065b
--- /dev/null
+++ b/clang/test/Preprocessor/stringize_space2.c
@@ -0,0 +1,6 @@
+/* RUN: clang -E %s | grep 'a c'
+ */
+#define t(x) #x
+t(a
+c)
+
OpenPOWER on IntegriCloud