From 80cdddc5046d4a0cd02a2a19cfb9ce70c3890c09 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Mon, 9 Apr 2012 16:37:11 +0000 Subject: 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. llvm-svn: 154325 --- clang/lib/Parse/Parser.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'clang/lib/Parse/Parser.cpp') diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index 2c6dff35b27..bc515cab5d5 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/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 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. -- cgit v1.2.3