diff options
author | Krasimir Georgiev <krasimir@google.com> | 2018-06-12 19:33:15 +0000 |
---|---|---|
committer | Krasimir Georgiev <krasimir@google.com> | 2018-06-12 19:33:15 +0000 |
commit | 4fc55a76b8d28335d2b57fe083bcc165c0061dab (patch) | |
tree | acb49e459329f6a9d632bb7cb61835a7e51a097f /clang/unittests | |
parent | 4872750dd38110a8f68eb70c39c1650d410b8564 (diff) | |
download | bcm5719-llvm-4fc55a76b8d28335d2b57fe083bcc165c0061dab.tar.gz bcm5719-llvm-4fc55a76b8d28335d2b57fe083bcc165c0061dab.zip |
[clang-format] Fix crash while reflowing backslash in comments
Summary:
The added test case was currently crashing with an assertion:
```
krasimir@krasimir> cat test.cc ~
// How to run:
// bbbbb run \
// rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr \
// <log_file> -- --output_directory="<output_directory>"
krasimir@krasimir> ~/work/llvm-build/bin/clang-format test.cc ~
clang-format: /usr/local/google/home/krasimir/work/llvm/tools/clang/lib/Format/WhitespaceManager.cpp:117: void clang::format::WhitespaceManager::calculateLineBreakInformation(): Assertion `PreviousOriginalWhitespaceEndOffset <= OriginalWhitespaceStartOffset' failed.
```
The root cause was that BreakableToken was not considering the case of a reflow between an unescaped newline in a line comment.
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D48089
llvm-svn: 334527
Diffstat (limited to 'clang/unittests')
-rw-r--r-- | clang/unittests/Format/FormatTestComments.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTestComments.cpp b/clang/unittests/Format/FormatTestComments.cpp index e89f1d9cde9..cacd2024fef 100644 --- a/clang/unittests/Format/FormatTestComments.cpp +++ b/clang/unittests/Format/FormatTestComments.cpp @@ -3090,6 +3090,21 @@ TEST_F(FormatTestComments, BreaksBeforeTrailingUnbreakableSequence) { getLLVMStyleWithColumns(23)); } +TEST_F(FormatTestComments, ReflowBackslashCrash) { +// clang-format off + EXPECT_EQ( +"// How to run:\n" +"// bbbbb run \\\n" +"// rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr\n" +"// \\ <log_file> -- --output_directory=\"<output_directory>\"", + format( +"// How to run:\n" +"// bbbbb run \\\n" +"// rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr \\\n" +"// <log_file> -- --output_directory=\"<output_directory>\"")); +// clang-format on +} + } // end namespace } // end namespace format } // end namespace clang |