On 01/02/14 20:09, Harald van Dijk wrote:
> Hi all,
> 
> Attached are my updated patches intended to fix various whitespace
> issues in clang, modified to take Justin Bogner's comments into account.

Yet somehow, I missed that I again used braces around a single statement
in an if. I've reworked it to remove the braces, moving the comment
above the if-statement for readability. This patch replaces the patch of
the same name in my previous message.

Cheers,
Harald van Dijk

> They are intended to ensure that whitespace is not inappropriately
> removed just because a macro or macro argument expansion is empty, and
> does get removed during token pasting.
> 
> I have moved the handling of invalid token pastes from
> TokenLexer::ExpandFunctionArguments to TokenLexer::Lex, so that it works
> for both object- and function-like macros, and both when ##'s operands
> use macro parameters and when they don't.
> 
> Do these changes look okay now? If so, would someone be so kind as to
> commit them for me?
> 
> Cheers,
> Harald van Dijk

>From bc172a6bb45d05d421799ac61f7988f158a04bf5 Mon Sep 17 00:00:00 2001
From: Harald van Dijk <[email protected]>
Date: Sat, 1 Feb 2014 19:48:30 +0100
Subject: [PATCH 5/5] Fix handling of whitespace in invalid token pastes

A comment in TokenLexer shows that the intent is that x ## y is always
permitted in assembler-with-cpp mode, even if the paste does not result
in a valid token, and that any whitespace before ## or before y is
ignored in that case. This is covered by existing tests.
---
 lib/Lex/TokenLexer.cpp                 | 14 +++++++-------
 test/Preprocessor/assembler-with-cpp.c |  6 +++---
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/lib/Lex/TokenLexer.cpp b/lib/Lex/TokenLexer.cpp
index 9913f30..fefc3c7 100644
--- a/lib/Lex/TokenLexer.cpp
+++ b/lib/Lex/TokenLexer.cpp
@@ -346,13 +346,6 @@ void TokenLexer::ExpandFunctionArguments() {
       // If this token (the macro argument) was supposed to get leading
       // whitespace, transfer this information onto the first token of the
       // expansion.
-      //
-      // Do not do this if the paste operator occurs before the macro argument,
-      // as in "A ## MACROARG".  In valid code, the first token will get
-      // smooshed onto the preceding one anyway (forming AMACROARG).  In
-      // assembler-with-cpp mode, invalid pastes are allowed through: in this
-      // case, we do not want the extra whitespace to be added.  For example,
-      // we want ". ## foo" -> ".foo" not ". foo".
       if (NextTokGetsSpace)
         ResultToks[ResultToks.size()-NumToks].setFlag(Token::LeadingSpace);
 
@@ -434,6 +427,13 @@ bool TokenLexer::Lex(Token &Tok) {
 
   bool TokenIsFromPaste = false;
 
+  // If this token follows a token paste (##) operator, we have an invalid
+  // paste.  In assembler-with-cpp mode, invalid pastes are allowed through: in
+  // this case, we do not want the extra whitespace to be added.  For example,
+  // we want ". ## foo" -> ".foo" not ". foo".
+  if (!isFirstToken && Tokens[CurToken - 2].is(tok::hashhash) && Macro)
+    Tok.clearFlag(Token::LeadingSpace);
+
   // If this token is followed by a token paste (##) operator, paste the tokens!
   // Note that ## is a normal token when not expanding a macro.
   if (!isAtEnd() && Tokens[CurToken].is(tok::hashhash) && Macro) {
diff --git a/test/Preprocessor/assembler-with-cpp.c b/test/Preprocessor/assembler-with-cpp.c
index f03cb06..e0a81f8 100644
--- a/test/Preprocessor/assembler-with-cpp.c
+++ b/test/Preprocessor/assembler-with-cpp.c
@@ -8,7 +8,7 @@
 // Invalid token pasting is ok. 
 #define A X ## .
 1: A
-// CHECK-Identifiers-False: 1: X .
+// CHECK-Identifiers-False: 1: X.
 
 // Line markers are not linemarkers in .S files, they are passed through.
 # 321
@@ -42,12 +42,12 @@
 #define M5() M4 ## (
 
 5: M5()
-// CHECK-Identifiers-False: 5: expanded (
+// CHECK-Identifiers-False: 5: expanded(
 
 // rdar://6804322
 #define FOO(name)  name ## $foo
 6: FOO(blarg)
-// CHECK-Identifiers-False: 6: blarg $foo
+// CHECK-Identifiers-False: 6: blarg$foo
 
 // RUN: %clang_cc1 -x assembler-with-cpp -fdollars-in-identifiers -E %s -o - | FileCheck -check-prefix=CHECK-Identifiers-True -strict-whitespace %s
 #define FOO(name)  name ## $foo
-- 
1.8.5.2

_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to