diff options
| author | Krasimir Georgiev <krasimir@google.com> | 2017-11-01 18:20:41 +0000 |
|---|---|---|
| committer | Krasimir Georgiev <krasimir@google.com> | 2017-11-01 18:20:41 +0000 |
| commit | 87b42549ee3a93dc17806b9e99fa699bb65a360c (patch) | |
| tree | 5c987d9ea43a1b63e8a70c3aee66ef0d5ec60739 | |
| parent | ca1aa83cbe22e5b3aa7345a6fd7d0e4d4b1f1d64 (diff) | |
| download | bcm5719-llvm-87b42549ee3a93dc17806b9e99fa699bb65a360c.tar.gz bcm5719-llvm-87b42549ee3a93dc17806b9e99fa699bb65a360c.zip | |
[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
llvm-svn: 317113
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 1b22e266007..bc8fef8bda9 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -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() { |

