diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp index b8a535b8d527f5..22509a50424659 100644 --- a/clang/lib/Format/UnwrappedLineFormatter.cpp +++ b/clang/lib/Format/UnwrappedLineFormatter.cpp @@ -1163,6 +1163,10 @@ class OptimizingLineFormatter : public LineFormatter { // While not empty, take first element and follow edges. while (!Queue.empty()) { + // Quit if we still haven't found a solution by now. + if (Count > 25000000) + return 0; + Penalty = Queue.top().first.first; StateNode *Node = Queue.top().second; if (!Node->State.NextToken) {