llvm-project/clang/unittests/Format
Richard Smith 1d2ae94b5d Fix mishandling of escaped newlines followed by newlines or nuls.
Previously, if an escaped newline was followed by a newline or a nul, we'd lex
the escaped newline as a bogus space character. This led to a bunch of
different broken corner cases:

For the pattern "\\\n\0#", we would then have a (horizontal) space whose
spelling ends in a newline, and would decide that the '#' is at the start of a
line, and incorrectly start preprocessing a directive in the middle of a
logical source line. If we were already in the middle of a directive, this
would result in our attempting to process multiple directives at the same time!
This resulted in crashes, asserts, and hangs on invalid input, as discovered by
fuzz-testing.

For the pattern "\\\n" at EOF (with an implicit following nul byte), we would
produce a bogus trailing space character with spelling "\\\n". This was mostly
harmless, but would lead to clang-format getting confused and misformatting in
rare cases. We now produce a trailing EOF token with spelling "\\\n",
consistent with our handling for other similar cases -- an escaped newline is
always part of the token containing the next character, if any.

For the pattern "\\\n\n", this was somewhat more benign, but would produce an
extraneous whitespace token to clients who care about preserving whitespace.
However, it turns out that our lexing for line comments was relying on this bug
due to an off-by-one error in its computation of the end of the comment, on the
slow path where the comment might contain escaped newlines.

llvm-svn: 300515
2017-04-17 23:44:51 +00:00
..
CMakeLists.txt [clang-format] Add a NamespaceEndCommentsFixer 2017-02-27 13:28:36 +00:00
CleanupTest.cpp [clang-format] revert an unintended change in r288493 and add a test case. 2016-12-19 10:41:05 +00:00
FormatTest.cpp [clang-format] Handle NSString literals by merging tokens. 2017-04-11 09:55:00 +00:00
FormatTestComments.cpp Fix mishandling of escaped newlines followed by newlines or nuls. 2017-04-17 23:44:51 +00:00
FormatTestJS.cpp clang-format: [JS] fix whitespace around "of" operator. 2017-04-05 10:56:07 +00:00
FormatTestJava.cpp [clang-format] Recognize Java logical shift assignment operator 2017-04-11 15:50:04 +00:00
FormatTestObjC.cpp clang-format: Make GetStyle return Expected<FormatStyle> instead of FormatStyle 2017-01-17 00:12:27 +00:00
FormatTestProto.cpp clang-format: Make it very slighly more expensive to wrap between "= {". 2017-03-14 00:40:32 +00:00
FormatTestSelective.cpp [clang-format] Implement comment reflowing. 2017-01-25 13:58:58 +00:00
FormatTestUtils.h Header guard canonicalization, clang part. 2014-08-13 16:25:19 +00:00
NamespaceEndCommentsFixerTest.cpp [clang-format] fix crash in NamespaceEndCommentsFixer (PR32438) 2017-04-04 20:11:13 +00:00
SortImportsTestJS.cpp clang-format: [JS] Fix line breaks before comments when sorting imports. 2016-09-19 07:02:34 +00:00
SortIncludesTest.cpp clang-format: Correctly calculate affected ranges when sorting #includes. 2016-08-30 21:33:41 +00:00