r202070 - If preprocessing results in a token with leading whitespace that was expanded

Richard Smith richard-llvm at metafoo.co.uk
Mon Feb 24 12:50:37 PST 2014


Author: rsmith
Date: Mon Feb 24 14:50:36 2014
New Revision: 202070

URL: http://llvm.org/viewvc/llvm-project?rev=202070&view=rev
Log:
If preprocessing results in a token with leading whitespace that was expanded
from a macro in column 0, ensure that we print whitespace before it in the -E
output. Patch by Harald van Dijk!

Modified:
    cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
    cfe/trunk/test/Preprocessor/macro_expand_empty.c

Modified: cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp?rev=202070&r1=202069&r2=202070&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp (original)
+++ cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp Mon Feb 24 14:50:36 2014
@@ -521,6 +521,13 @@ bool PrintPPOutputPPCallbacks::HandleFir
   // indented for easy reading.
   unsigned ColNo = SM.getExpansionColumnNumber(Tok.getLocation());
 
+  // The first token on a line can have a column number of 1, yet still expect
+  // leading white space, if a macro expansion in column 1 starts with an empty
+  // macro argument, or an empty nested macro expansion. In this case, move the
+  // token to column 2.
+  if (ColNo == 1 && Tok.hasLeadingSpace())
+    ColNo = 2;
+
   // This hack prevents stuff like:
   // #define HASH #
   // HASH define foo bar

Modified: cfe/trunk/test/Preprocessor/macro_expand_empty.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/macro_expand_empty.c?rev=202070&r1=202069&r2=202070&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/macro_expand_empty.c (original)
+++ cfe/trunk/test/Preprocessor/macro_expand_empty.c Mon Feb 24 14:50:36 2014
@@ -17,5 +17,5 @@ IDENTITY0()
 #define FOO() BAR() second
 #define BAR()
 first // CHECK: {{^}}first{{$}}
-FOO() // CHECK: second
+FOO() // CHECK: {{^}} second{{$}}
 third // CHECK: {{^}}third{{$}}





More information about the cfe-commits mailing list