diff options
| author | Daniel Jasper <djasper@google.com> | 2013-10-11 19:45:02 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2013-10-11 19:45:02 +0000 |
| commit | 1d82b1a33bcfe85f4834fb6920517ed07e9355d3 (patch) | |
| tree | 017522f67c606d2cf141045b91846e0ff23def96 /lib/Format/Format.cpp | |
| parent | d6b52974a74b1819f62a034a6a4939e8d00a04bd (diff) | |
| download | clang-1d82b1a33bcfe85f4834fb6920517ed07e9355d3.tar.gz clang-1d82b1a33bcfe85f4834fb6920517ed07e9355d3.tar.bz2 clang-1d82b1a33bcfe85f4834fb6920517ed07e9355d3.tar.xz | |
clang-format: Don't remove 'unknown' tokens.
In certain macros or incorrect string literals, the token stream can
contain 'unknown' tokens, e.g. a single backslash or a set of empty
ticks. clang-format simply treated them as whitespace and removed them
prior to this patch.
This fixes llvm.org/PR17215
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192490 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/Format.cpp')
| -rw-r--r-- | lib/Format/Format.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 129c119532..7fc66167f0 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -691,18 +691,32 @@ private: FormatTok->LastNewlineOffset = WhitespaceLength + i + 1; Column = 0; break; + case '\r': + case '\f': + case '\v': + Column = 0; + break; case ' ': ++Column; break; case '\t': Column += Style.TabWidth - Column % Style.TabWidth; break; + case '\\': + ++Column; + if (i + 1 == e || (FormatTok->TokenText[i + 1] != '\r' && + FormatTok->TokenText[i + 1] != '\n')) + FormatTok->Type = TT_ImplicitStringLiteral; + break; default: + FormatTok->Type = TT_ImplicitStringLiteral; ++Column; break; } } + if (FormatTok->Type == TT_ImplicitStringLiteral) + break; WhitespaceLength += FormatTok->Tok.getLength(); readRawToken(*FormatTok); |
