[clang-tidy] Don't reinvent the wheel, use existing log2 functions.

This also makes the code ready for int128, even though I think it's
currently impossible to get an int128 into this code path.

llvm-svn: 324079
This commit is contained in:
Benjamin Kramer 2018-02-02 13:23:21 +00:00
parent c2dfd502a2
commit 10db8d6dbc
1 changed files with 1 additions and 8 deletions

View File

@ -966,13 +966,6 @@ void RedundantExpressionCheck::checkRelationalExpr(
}
}
unsigned intLog2(uint64_t X) {
unsigned Result = 0;
while (X >>= 1)
++Result;
return Result;
}
void RedundantExpressionCheck::check(const MatchFinder::MatchResult &Result) {
if (const auto *BinOp = Result.Nodes.getNodeAs<BinaryOperator>("binary")) {
// If the expression's constants are macros, check whether they are
@ -1049,7 +1042,7 @@ void RedundantExpressionCheck::check(const MatchFinder::MatchResult &Result) {
// If ShiftingConst is shifted left with more bits than the position of the
// leftmost 1 in the bit representation of AndValue, AndConstant is
// ineffective.
if (intLog2(AndValue.getExtValue()) >= ShiftingValue)
if (AndValue.getActiveBits() > ShiftingValue)
return;
auto Diag = diag(BinaryAndExpr->getOperatorLoc(),