diff options
author | David Blaikie <dblaikie@gmail.com> | 2012-04-09 16:37:11 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2012-04-09 16:37:11 +0000 |
commit | eb52f86a62db523e3c993686b3ed92c55d59d53c (patch) | |
tree | 5134ec06185e7f16efc2e2cac6543cd84f0a45a5 /lib/Parse | |
parent | 649ee3fec12dcf7167630ff88087ad116e9eefa6 (diff) |
Fix bugs found by -Wconstant-conversion improvements currently under review.
Specifically, using a an integer outside [0, 1] as a boolean constant seems to
be an easy mistake to make with things like "x == a || b" where the author
intended "x == a || x == b".
The bug caused by calling SkipUntil with three token kinds was also identified
by a VC diagnostic & reported by Francois Pichet as review feedback for my
commit r154163. I've included test cases to verify the error recovery that was
broken/poorly implemented due to this bug.
The other fix (lib/Sema/SemaExpr.cpp) seems like that code was never actually
reached in any of Clang's tests & is related to Objective C features I'm not
familiar with, so I've not been able to construct a test case for it. Perhaps
someone else can.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154325 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse')
-rw-r--r-- | lib/Parse/ParseTemplate.cpp | 32 | ||||
-rw-r--r-- | lib/Parse/ParseTentative.cpp | 4 | ||||
-rw-r--r-- | lib/Parse/Parser.cpp | 7 |
3 files changed, 19 insertions, 24 deletions
diff --git a/lib/Parse/ParseTemplate.cpp b/lib/Parse/ParseTemplate.cpp index 9d5c62567e..61cd9f2119 100644 --- a/lib/Parse/ParseTemplate.cpp +++ b/lib/Parse/ParseTemplate.cpp @@ -309,18 +309,19 @@ bool Parser::ParseTemplateParameters(unsigned Depth, LAngleLoc = ConsumeToken(); // Try to parse the template parameter list. - if (Tok.is(tok::greater)) + bool Failed = false; + if (!Tok.is(tok::greater) && !Tok.is(tok::greatergreater)) + Failed = ParseTemplateParameterList(Depth, TemplateParams); + + if (Tok.is(tok::greatergreater)) { + Tok.setKind(tok::greater); + RAngleLoc = Tok.getLocation(); + Tok.setLocation(Tok.getLocation().getLocWithOffset(1)); + } else if (Tok.is(tok::greater)) RAngleLoc = ConsumeToken(); - else if (ParseTemplateParameterList(Depth, TemplateParams)) { - if (Tok.is(tok::greatergreater)) { - Tok.setKind(tok::greater); - Tok.setLocation(Tok.getLocation().getLocWithOffset(1)); - } else if (Tok.is(tok::greater)) - RAngleLoc = ConsumeToken(); - else { - Diag(Tok.getLocation(), diag::err_expected_greater); - return true; - } + else if (Failed) { + Diag(Tok.getLocation(), diag::err_expected_greater); + return true; } return false; } @@ -356,10 +357,8 @@ Parser::ParseTemplateParameterList(unsigned Depth, // Somebody probably forgot to close the template. Skip ahead and // try to get out of the expression. This error is currently // subsumed by whatever goes on in ParseTemplateParameter. - // TODO: This could match >>, and it would be nice to avoid those - // silly errors with template <vec<T>>. Diag(Tok.getLocation(), diag::err_expected_comma_greater); - SkipUntil(tok::greater, true, true); + SkipUntil(tok::comma, tok::greater, tok::greatergreater, true, true); return false; } } @@ -607,10 +606,7 @@ Parser::ParseTemplateTemplateParameter(unsigned Depth, unsigned Position) { if (DefaultArg.isInvalid()) { Diag(Tok.getLocation(), diag::err_default_template_template_parameter_not_template); - static const tok::TokenKind EndToks[] = { - tok::comma, tok::greater, tok::greatergreater - }; - SkipUntil(EndToks, 3, true, true); + SkipUntil(tok::comma, tok::greater, tok::greatergreater, true, true); } } diff --git a/lib/Parse/ParseTentative.cpp b/lib/Parse/ParseTentative.cpp index 73501e58ca..b650169b25 100644 --- a/lib/Parse/ParseTentative.cpp +++ b/lib/Parse/ParseTentative.cpp @@ -1268,8 +1268,8 @@ Parser::TPResult Parser::TryParseParameterDeclarationClause() { if (Tok.is(tok::equal)) { // '=' assignment-expression // Parse through assignment-expression. - tok::TokenKind StopToks[2] ={ tok::comma, tok::r_paren }; - if (!SkipUntil(StopToks, 2, true/*StopAtSemi*/, true/*DontConsume*/)) + if (!SkipUntil(tok::comma, tok::r_paren, true/*StopAtSemi*/, + true/*DontConsume*/)) return TPResult::Error(); } diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index 2c6dff35b2..bc515cab5d 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -213,15 +213,14 @@ bool Parser::ExpectAndConsumeSemi(unsigned DiagID) { /// /// If SkipUntil finds the specified token, it returns true, otherwise it /// returns false. -bool Parser::SkipUntil(const tok::TokenKind *Toks, unsigned NumToks, - bool StopAtSemi, bool DontConsume, - bool StopAtCodeCompletion) { +bool Parser::SkipUntil(ArrayRef<tok::TokenKind> Toks, bool StopAtSemi, + bool DontConsume, bool StopAtCodeCompletion) { // We always want this function to skip at least one token if the first token // isn't T and if not at EOF. bool isFirstTokenSkipped = true; while (1) { // If we found one of the tokens, stop and return true. - for (unsigned i = 0; i != NumToks; ++i) { + for (unsigned i = 0, NumToks = Toks.size(); i != NumToks; ++i) { if (Tok.is(Toks[i])) { if (DontConsume) { // Noop, don't consume the token. |