From: Daniel Jasper Date: Thu, 30 May 2013 06:40:07 +0000 (+0000) Subject: Fix crasher when formatting certain block comments. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e2c482f3720261dea180400816d4572d1986f423;p=clang Fix crasher when formatting certain block comments. Smallest reproduction: /* ** */ git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182913 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/BreakableToken.cpp b/lib/Format/BreakableToken.cpp index 5c3ad9cee2..10ba1f39a5 100644 --- a/lib/Format/BreakableToken.cpp +++ b/lib/Format/BreakableToken.cpp @@ -337,6 +337,11 @@ BreakableBlockComment::replaceWhitespaceBefore(unsigned LineIndex, // contain a trailing whitespace. Prefix = Prefix.substr(0, 1); } + } else { + if (StartOfLineColumn[LineIndex] == 1) { + // This lines starts immediately after the decorating *. + Prefix = Prefix.substr(0, 1); + } } unsigned WhitespaceOffsetInToken = diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 1f4f4806c3..b2e53a5334 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -3640,6 +3640,7 @@ TEST_F(FormatTest, BlockComments) { format("#define A\n" "/* */someCall(parameter);", getLLVMStyleWithColumns(15))); + EXPECT_EQ("/*\n**\n*/", format("/*\n**\n*/")); FormatStyle NoBinPacking = getLLVMStyle(); NoBinPacking.BinPackParameters = false;