diff options
author | Daniel Jasper <djasper@google.com> | 2015-05-06 08:38:24 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2015-05-06 08:38:24 +0000 |
commit | 4d9ec17f1e7dd096c3b04222e169ddb00a7f353d (patch) | |
tree | a94bb18a99a4d6a75d13e3db9fea04b196822ea1 /clang/lib/Format/TokenAnnotator.cpp | |
parent | 9d37c4102244d0198deb5fe1af49469714a56c20 (diff) | |
download | bcm5719-llvm-4d9ec17f1e7dd096c3b04222e169ddb00a7f353d.tar.gz bcm5719-llvm-4d9ec17f1e7dd096c3b04222e169ddb00a7f353d.zip |
clang-format: Prevent exponential runtime in token annotator.
llvm-svn: 236577
Diffstat (limited to 'clang/lib/Format/TokenAnnotator.cpp')
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 45193572ca1..39ac66b27fa 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -15,6 +15,7 @@ #include "TokenAnnotator.h" #include "clang/Basic/SourceManager.h" +#include "llvm/ADT/SmallPtrSet.h" #include "llvm/Support/Debug.h" #define DEBUG_TYPE "format-token-annotator" @@ -495,13 +496,15 @@ private: return false; break; case tok::less: - if ((!Tok->Previous || + if (!NonTemplateLess.count(Tok) && + (!Tok->Previous || (!Tok->Previous->Tok.isLiteral() && !(Tok->Previous->is(tok::r_paren) && Contexts.size() > 1))) && parseAngle()) { Tok->Type = TT_TemplateOpener; } else { Tok->Type = TT_BinaryOperator; + NonTemplateLess.insert(Tok); CurrentToken = Tok; next(); } @@ -648,6 +651,7 @@ private: public: LineType parseLine() { + NonTemplateLess.clear(); if (CurrentToken->is(tok::hash)) return parsePreprocessorDirective(); @@ -1160,6 +1164,12 @@ private: FormatToken *CurrentToken; bool AutoFound; const AdditionalKeywords &Keywords; + + // Set of "<" tokens that do not open a template parameter list. If parseAngle + // determines that a specific token can't be a template opener, it will make + // same decision irrespective of the decisions for tokens leading up to it. + // Store this information to prevent this from causing exponential runtime. + llvm::SmallPtrSet<FormatToken *, 16> NonTemplateLess; }; static const int PrecedenceUnaryOperator = prec::PointerToMember + 1; |