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!

llvm-svn: 202070
This commit is contained in:
Richard Smith 2014-02-24 20:50:36 +00:00
parent dec2c8657e
commit 5b2f7c5f60
2 changed files with 8 additions and 1 deletions

View File

@ -521,6 +521,13 @@ bool PrintPPOutputPPCallbacks::HandleFirstTokOnLine(Token &Tok) {
// 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

View File

@ -17,5 +17,5 @@ IDENTITY0()
#define FOO() BAR() second
#define BAR()
first // CHECK: {{^}}first{{$}}
FOO() // CHECK: second
FOO() // CHECK: {{^}} second{{$}}
third // CHECK: {{^}}third{{$}}