summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2016-10-31 13:23:00 +0000
committerDaniel Jasper <djasper@google.com>2016-10-31 13:23:00 +0000
commitfda47cd8739d6e195bc00b0f565a00f07573ad6d (patch)
tree7c516e0a08c4064d42b69b9b746de9abe7e72299 /clang/unittests/Format
parenteb886635d9d5b81edadc61a3db38d119791d7c9c (diff)
downloadbcm5719-llvm-fda47cd8739d6e195bc00b0f565a00f07573ad6d.tar.gz
bcm5719-llvm-fda47cd8739d6e195bc00b0f565a00f07573ad6d.zip
Skip over AnnotatedLines with >50 levels of nesting; don't format them.
Reasoning: - ExpressionParser uses a lot of stack for these, bad in some environments. - Our formatting algorithm is N^3 and gets really slow. - The resulting formatting is unlikely to be any good. - This is probably generated code we're formatting by accident. We treat these as unparseable, and signal incomplete formatting. 50 is an arbitrary number, I've only seen real problems from ~150 levels. Patch by Sam McCall. Thank you. llvm-svn: 285570
Diffstat (limited to 'clang/unittests/Format')
-rw-r--r--clang/unittests/Format/FormatTest.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index ee08121c5ad..b95a29f781c 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -7179,6 +7179,30 @@ TEST_F(FormatTest, SpecialTokensAtEndOfLine) {
verifyFormat("operator");
}
+TEST_F(FormatTest, SkipsDeeplyNestedLines) {
+ // This code would be painfully slow to format if we didn't skip it.
+ std::string Code("A(A(A(A(A(A(A(A(A(A(A(A(A(A(A(A(A(A(A(A(\n" // 20x
+ "A(A(A(A(A(A(A(A(A(A(A(A(A(A(A(A(A(A(A(A(\n"
+ "A(A(A(A(A(A(A(A(A(A(A(A(A(A(A(A(A(A(A(A(\n"
+ "A(A(A(A(A(A(A(A(A(A(A(A(A(A(A(A(A(A(A(A(\n"
+ "A(A(A(A(A(A(A(A(A(A(A(A(A(A(A(A(A(A(A(A(\n"
+ "A(1, 1)\n"
+ ", 1), 1), 1), 1), 1), 1), 1), 1), 1), 1)\n" // 10x
+ ", 1), 1), 1), 1), 1), 1), 1), 1), 1), 1)\n"
+ ", 1), 1), 1), 1), 1), 1), 1), 1), 1), 1)\n"
+ ", 1), 1), 1), 1), 1), 1), 1), 1), 1), 1)\n"
+ ", 1), 1), 1), 1), 1), 1), 1), 1), 1), 1)\n"
+ ", 1), 1), 1), 1), 1), 1), 1), 1), 1), 1)\n"
+ ", 1), 1), 1), 1), 1), 1), 1), 1), 1), 1)\n"
+ ", 1), 1), 1), 1), 1), 1), 1), 1), 1), 1)\n"
+ ", 1), 1), 1), 1), 1), 1), 1), 1), 1), 1)\n"
+ ", 1), 1), 1), 1), 1), 1), 1), 1), 1), 1);\n");
+ // Deeply nested part is untouched, rest is formatted.
+ EXPECT_EQ(std::string("int i;\n") + Code + "int j;\n",
+ format(std::string("int i;\n") + Code + "int j;\n",
+ getLLVMStyle(), IC_ExpectIncomplete));
+}
+
//===----------------------------------------------------------------------===//
// Objective-C tests.
//===----------------------------------------------------------------------===//
OpenPOWER on IntegriCloud