Author: krasimir Date: Wed Nov 1 11:20:41 2017 New Revision: 317113 URL: http://llvm.org/viewvc/llvm-project?rev=317113&view=rev Log: [clang-format] Make parseUnaryOperator non-recursive, NFCI
Summary: This patch makes the implementation of parseUnaryOperator non-recursive. We had a problem with a file starting with tens of thousands of +'es and -'es which caused clang-format to stack overflow. Reviewers: bkramer Reviewed By: bkramer Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D39498 Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=317113&r1=317112&r2=317113&view=diff ============================================================================== --- cfe/trunk/lib/Format/TokenAnnotator.cpp (original) +++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Nov 1 11:20:41 2017 @@ -1662,17 +1662,15 @@ private: /// \brief Parse unary operator expressions and surround them with fake /// parentheses if appropriate. void parseUnaryOperator() { - if (!Current || Current->isNot(TT_UnaryOperator)) { - parse(PrecedenceArrowAndPeriod); - return; + llvm::SmallVector<FormatToken *, 2> Tokens; + while (Current && Current->is(TT_UnaryOperator)) { + Tokens.push_back(Current); + next(); } - - FormatToken *Start = Current; - next(); - parseUnaryOperator(); - - // The actual precedence doesn't matter. - addFakeParenthesis(Start, prec::Unknown); + parse(PrecedenceArrowAndPeriod); + for (FormatToken *Token : llvm::reverse(Tokens)) + // The actual precedence doesn't matter. + addFakeParenthesis(Token, prec::Unknown); } void parseConditionalExpr() { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits