]> granicus.if.org Git - clang/commitdiff
Fix crasher when formatting certain block comments.
authorDaniel Jasper <djasper@google.com>
Thu, 30 May 2013 06:40:07 +0000 (06:40 +0000)
committerDaniel Jasper <djasper@google.com>
Thu, 30 May 2013 06:40:07 +0000 (06:40 +0000)
Smallest reproduction:
/*
**
*/

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182913 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/BreakableToken.cpp
unittests/Format/FormatTest.cpp

index 5c3ad9cee2bc3aed1e1389f07d02803cf34759c0..10ba1f39a55554edeceb4f8c873f48423b10071a 100644 (file)
@@ -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 =
index 1f4f4806c3b7f2c12b5c81aefc80499340cac68e..b2e53a53348dbf8b32c76ddd2b92474a49dac352 100644 (file)
@@ -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;