summaryrefslogtreecommitdiffstats
path: root/clang/lib/Lex/TokenLexer.cpp
diff options
context:
space:
mode:
authorWill Wilson <will@indefiant.com>2015-04-17 12:43:57 +0000
committerWill Wilson <will@indefiant.com>2015-04-17 12:43:57 +0000
commitdb2588ab828b9a689af33ef85b63a20fd494c843 (patch)
tree60b25dcc4bff0ad8fe10786c1b504f5645a7c61b /clang/lib/Lex/TokenLexer.cpp
parent7f4e07befc5a22b48e30aa8abc4fe98b22bfa784 (diff)
downloadbcm5719-llvm-db2588ab828b9a689af33ef85b63a20fd494c843.tar.gz
bcm5719-llvm-db2588ab828b9a689af33ef85b63a20fd494c843.zip
[MSVC] Mimic MSVC whitespace collapse for incompatible token pasting
In public MS headers for XAudio, clang would fail to generate a valid UUID due to the UUID components being combined with the '-' UUID separators. Clang would attempting to recover but would preserve the leading whitespace from the tokens after each failed paste leading to spaces creeping into the UUID and causing an error in the __declspace(uuid()) parsing. Reference: Microsoft DirectX SDK (June 2010)\Include\XAudio2.h(51) Resolves http://llvm.org/pr23071 llvm-svn: 235186
Diffstat (limited to 'clang/lib/Lex/TokenLexer.cpp')
-rw-r--r--clang/lib/Lex/TokenLexer.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/clang/lib/Lex/TokenLexer.cpp b/clang/lib/Lex/TokenLexer.cpp
index 23d72814f31..83efbab7613 100644
--- a/clang/lib/Lex/TokenLexer.cpp
+++ b/clang/lib/Lex/TokenLexer.cpp
@@ -521,6 +521,13 @@ bool TokenLexer::Lex(Token &Tok) {
/// are more ## after it, chomp them iteratively. Return the result as Tok.
/// If this returns true, the caller should immediately return the token.
bool TokenLexer::PasteTokens(Token &Tok) {
+ // MSVC: If previous token was pasted, this must be a recovery from an invalid
+ // paste operation. Ignore spaces before this token to mimic MSVC output.
+ // Required for generating valid UUID strings in some MS headers.
+ if (PP.getLangOpts().MicrosoftExt && (CurToken >= 2) &&
+ Tokens[CurToken - 2].is(tok::hashhash))
+ Tok.clearFlag(Token::LeadingSpace);
+
SmallString<128> Buffer;
const char *ResultTokStrPtr = nullptr;
SourceLocation StartLoc = Tok.getLocation();
OpenPOWER on IntegriCloud