summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format
diff options
context:
space:
mode:
authorPaul Hoad <mydeveloperday@gmail.com>2019-09-18 18:57:09 +0000
committerPaul Hoad <mydeveloperday@gmail.com>2019-09-18 18:57:09 +0000
commit79983be5a027c0ff8a7ef7a8f67481ce61efc523 (patch)
tree3e5eeaedc9cdc0363ed935223dcf74da669aedad /clang/unittests/Format
parentba4cad9039660d322937f7f44bcb30b4849c3d58 (diff)
downloadbcm5719-llvm-79983be5a027c0ff8a7ef7a8f67481ce61efc523.tar.gz
bcm5719-llvm-79983be5a027c0ff8a7ef7a8f67481ce61efc523.zip
[clang-format][PR41964] Fix crash with SIGFPE when TabWidth is set to 0 and line starts with tab
Summary: clang-format 8.0 crashes with SIGFPE (floating point exception) when formatting following file: app.cpp: void a() { //line starts with '\t' } $ clang-format -style='{TabWidth: 0}' app.cpp Reviewers: owenpan, klimek, russellmcc, timwoj Reviewed By: klimek Subscribers: cfe-commits Tags: #clang-tools-extra, #clang Differential Revision: https://reviews.llvm.org/D67670 llvm-svn: 372246
Diffstat (limited to 'clang/unittests/Format')
-rw-r--r--clang/unittests/Format/FormatTest.cpp73
1 files changed, 73 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index b1fcd39a49a..dc20faf70c5 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -9877,6 +9877,79 @@ TEST_F(FormatTest, ConfigurableUseOfTab) {
Tab);
}
+TEST_F(FormatTest, ZeroTabWidth) {
+ FormatStyle Tab = getLLVMStyleWithColumns(42);
+ Tab.IndentWidth = 8;
+ Tab.UseTab = FormatStyle::UT_Never;
+ Tab.TabWidth = 0;
+ EXPECT_EQ("void a(){\n"
+ " // line starts with '\t'\n"
+ "};",
+ format("void a(){\n"
+ "\t// line starts with '\t'\n"
+ "};",
+ Tab));
+
+ EXPECT_EQ("void a(){\n"
+ " // line starts with '\t'\n"
+ "};",
+ format("void a(){\n"
+ "\t\t// line starts with '\t'\n"
+ "};",
+ Tab));
+
+ Tab.UseTab = FormatStyle::UT_ForIndentation;
+ EXPECT_EQ("void a(){\n"
+ " // line starts with '\t'\n"
+ "};",
+ format("void a(){\n"
+ "\t// line starts with '\t'\n"
+ "};",
+ Tab));
+
+ EXPECT_EQ("void a(){\n"
+ " // line starts with '\t'\n"
+ "};",
+ format("void a(){\n"
+ "\t\t// line starts with '\t'\n"
+ "};",
+ Tab));
+
+ Tab.UseTab = FormatStyle::UT_ForContinuationAndIndentation;
+ EXPECT_EQ("void a(){\n"
+ " // line starts with '\t'\n"
+ "};",
+ format("void a(){\n"
+ "\t// line starts with '\t'\n"
+ "};",
+ Tab));
+
+ EXPECT_EQ("void a(){\n"
+ " // line starts with '\t'\n"
+ "};",
+ format("void a(){\n"
+ "\t\t// line starts with '\t'\n"
+ "};",
+ Tab));
+
+ Tab.UseTab = FormatStyle::UT_Always;
+ EXPECT_EQ("void a(){\n"
+ "// line starts with '\t'\n"
+ "};",
+ format("void a(){\n"
+ "\t// line starts with '\t'\n"
+ "};",
+ Tab));
+
+ EXPECT_EQ("void a(){\n"
+ "// line starts with '\t'\n"
+ "};",
+ format("void a(){\n"
+ "\t\t// line starts with '\t'\n"
+ "};",
+ Tab));
+}
+
TEST_F(FormatTest, CalculatesOriginalColumn) {
EXPECT_EQ("\"qqqqqqqqqqqqqqqqqqqqqqqqqq\\\n"
"q\"; /* some\n"
OpenPOWER on IntegriCloud