summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/Format.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-10-11 19:45:02 +0000
committerDaniel Jasper <djasper@google.com>2013-10-11 19:45:02 +0000
commit877615ccfdaadc154420dcc5a2939c56bf5fa4aa (patch)
tree880f137cbcf974224a3f0727b7f74e0fafdbe58e /clang/lib/Format/Format.cpp
parent8c46baca65347ec1334bde704a15242e2738d937 (diff)
downloadbcm5719-llvm-877615ccfdaadc154420dcc5a2939c56bf5fa4aa.tar.gz
bcm5719-llvm-877615ccfdaadc154420dcc5a2939c56bf5fa4aa.zip
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 llvm-svn: 192490
Diffstat (limited to 'clang/lib/Format/Format.cpp')
-rw-r--r--clang/lib/Format/Format.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 129c119532e..7fc66167f08 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/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);
OpenPOWER on IntegriCloud