From 4fc55a76b8d28335d2b57fe083bcc165c0061dab Mon Sep 17 00:00:00 2001 From: Krasimir Georgiev Date: Tue, 12 Jun 2018 19:33:15 +0000 Subject: [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 \ // -- --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 --- clang/unittests/Format/FormatTestComments.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'clang/unittests') 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" +"// \\ -- --output_directory=\"\"", + format( +"// How to run:\n" +"// bbbbb run \\\n" +"// rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr \\\n" +"// -- --output_directory=\"\"")); +// clang-format on +} + } // end namespace } // end namespace format } // end namespace clang -- cgit v1.2.3