Author: alexfh Date: Tue Apr 15 09:52:43 2014 New Revision: 206295 URL: http://llvm.org/viewvc/llvm-project?rev=206295&view=rev Log: Fix assertion when breaking string literals with tab characters.
Summary: Fixes http://llvm.org/PR19368 Reviewers: djasper, klimek Reviewed By: klimek CC: cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D3379 Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp cfe/trunk/unittests/Format/FormatTest.cpp Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=206295&r1=206294&r2=206295&view=diff ============================================================================== --- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original) +++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Tue Apr 15 09:52:43 2014 @@ -961,6 +961,12 @@ unsigned ContinuationIndenter::breakProt break; } + // When breaking before a tab character, it may be moved by a few columns, + // but will still be expanded to the next tab stop, so we don't save any + // columns. + if (NewRemainingTokenColumns == RemainingTokenColumns) + break; + assert(NewRemainingTokenColumns < RemainingTokenColumns); if (!DryRun) Token->insertBreak(LineIndex, TailOffset, Split, Whitespaces); Modified: cfe/trunk/unittests/Format/FormatTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=206295&r1=206294&r2=206295&view=diff ============================================================================== --- cfe/trunk/unittests/Format/FormatTest.cpp (original) +++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Apr 15 09:52:43 2014 @@ -6366,7 +6366,7 @@ TEST_F(FormatTest, ReformatRegionAdjusts 67, 0, getLLVMStyle())); } -TEST_F(FormatTest, BreakStringLiterals) { +TEST_F(FormatTest, BreaksStringLiterals) { EXPECT_EQ("\"some text \"\n" "\"other\";", format("\"some text other\";", getLLVMStyleWithColumns(12))); @@ -6526,6 +6526,16 @@ TEST_F(FormatTest, BreakStringLiterals) format("#define A \"some text other\";", AlignLeft)); } +TEST_F(FormatTest, BreaksStringLiteralsWithTabs) { + EXPECT_EQ( + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "(\n" + " \"x\t\");", + format("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaa(" + "\"x\t\");")); +} + TEST_F(FormatTest, BreaksWideAndNSStringLiterals) { EXPECT_EQ( "u8\"utf8 string \"\n" _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
