r182913 - Fix crasher when formatting certain block comments.
Daniel Jasper
djasper at google.com
Wed May 29 23:40:07 PDT 2013
Author: djasper
Date: Thu May 30 01:40:07 2013
New Revision: 182913
URL: http://llvm.org/viewvc/llvm-project?rev=182913&view=rev
Log:
Fix crasher when formatting certain block comments.
Smallest reproduction:
/*
**
*/
Modified:
cfe/trunk/lib/Format/BreakableToken.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/BreakableToken.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/BreakableToken.cpp?rev=182913&r1=182912&r2=182913&view=diff
==============================================================================
--- cfe/trunk/lib/Format/BreakableToken.cpp (original)
+++ cfe/trunk/lib/Format/BreakableToken.cpp Thu May 30 01:40:07 2013
@@ -337,6 +337,11 @@ BreakableBlockComment::replaceWhitespace
// 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 =
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=182913&r1=182912&r2=182913&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu May 30 01:40:07 2013
@@ -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;
More information about the cfe-commits
mailing list