<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Feb 4, 2014 at 11:18 AM, Justin Bogner <span dir="ltr"><<a href="mailto:mail@justinbogner.com" target="_blank">mail@justinbogner.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: bogner<br>
Date: Tue Feb  4 13:18:35 2014<br>
New Revision: 200787<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=200787&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=200787&view=rev</a><br>
Log:<br>
Fix whitespace handling in empty macro expansions<br>
<br>
When a macro expansion does not result in any tokens, and the macro name<br>
is preceded by whitespace, the whitespace should be passed to the first<br>
token that follows the macro expansion. Similarly when a macro expansion<br>
ends with a placemarker token, and that placemarker token is preceded by<br>
whitespace. This worked already for top-level macro expansions, but is<br>
now extended to also work for nested macro expansions.<br>
<br>
Patch by Harald van Dijk!<br>
<br>
Modified:<br>
    cfe/trunk/lib/Lex/TokenLexer.cpp<br>
    cfe/trunk/test/Preprocessor/macro_space.c<br>
<br>
Modified: cfe/trunk/lib/Lex/TokenLexer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/TokenLexer.cpp?rev=200787&r1=200786&r2=200787&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/TokenLexer.cpp?rev=200787&r1=200786&r2=200787&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/lib/Lex/TokenLexer.cpp (original)<br>
+++ cfe/trunk/lib/Lex/TokenLexer.cpp Tue Feb  4 13:18:35 2014<br>
@@ -477,9 +477,13 @@ bool TokenLexer::Lex(Token &Tok) {<br>
   if (isFirstToken) {<br>
     Tok.setFlagValue(Token::StartOfLine , AtStartOfLine);<br>
     Tok.setFlagValue(Token::LeadingSpace, HasLeadingSpace);<br>
-    AtStartOfLine = false;<br>
-    HasLeadingSpace = false;<br>
+  } else {<br>
+    // If this is not the first token, we may still need to pass through<br>
+    // leading whitespace if we've expanded a macro.<br>
+    if (HasLeadingSpace) Tok.setFlag(Token::LeadingSpace);<br></blockquote><div><br></div><div>Do we need to do this for AtStartOfLine too? What happens if we have a macro at the start of a line that expands to no tokens, within a TokenLexer? (I guess this can't happen within a macro expansion, since no tokens there are ever at the start of a line after line-splicing, but we use TokenLexers in other cases too).</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
   }<br>
+  AtStartOfLine = false;<br>
+  HasLeadingSpace = false;<br>
<br>
   // Handle recursive expansion!<br>
   if (!Tok.isAnnotation() && Tok.getIdentifierInfo() != 0) {<br>
<br>
Modified: cfe/trunk/test/Preprocessor/macro_space.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/macro_space.c?rev=200787&r1=200786&r2=200787&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/macro_space.c?rev=200787&r1=200786&r2=200787&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/test/Preprocessor/macro_space.c (original)<br>
+++ cfe/trunk/test/Preprocessor/macro_space.c Tue Feb  4 13:18:35 2014<br>
@@ -1,6 +1,36 @@<br>
 // RUN: %clang_cc1 -E %s | FileCheck --strict-whitespace %s<br>
<br>
-#define XX<br>
-! XX,<br>
+#define FOO1()<br>
+#define FOO2(x)x<br>
+#define FOO3(x) x<br>
+#define FOO4(x)x x<br>
+#define FOO5(x) x x<br>
+#define FOO6(x) [x]<br>
+#define FOO7(x) [ x]<br>
+#define FOO8(x) [x ]<br>
<br>
-// CHECK: {{^}}! ,{{$}}<br>
+#define TEST(FOO,x) FOO <FOO()> < FOO()> <FOO ()> <FOO( )> <FOO() > <FOO()x> <FOO() x> < FOO()x><br>
+<br>
+TEST(FOO1,)<br>
+// CHECK: FOO1 <> < > <> <> < > <> < > < ><br>
+<br>
+TEST(FOO2,)<br>
+// CHECK: FOO2 <> < > <> <> < > <> < > < ><br>
+<br>
+TEST(FOO3,)<br>
+// CHECK: FOO3 <> < > <> <> < > <> < > < ><br>
+<br>
+TEST(FOO4,)<br>
+// CHECK: FOO4 < > < > < > < > < > < > < > < ><br>
+<br>
+TEST(FOO5,)<br>
+// CHECK: FOO5 < > < > < > < > < > < > < > < ><br>
+<br>
+TEST(FOO6,)<br>
+// CHECK: FOO6 <[]> < []> <[]> <[]> <[] > <[]> <[] > < []><br>
+<br>
+TEST(FOO7,)<br>
+// CHECK: FOO7 <[ ]> < [ ]> <[ ]> <[ ]> <[ ] > <[ ]> <[ ] > < [ ]><br>
+<br>
+TEST(FOO8,)<br>
+// CHECK: FOO8 <[ ]> < [ ]> <[ ]> <[ ]> <[ ] > <[ ]> <[ ] > < [ ]><br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>