[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
diff --git a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
index 34d04db..635c29f 100644
--- a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
@@ -966,13 +966,6 @@
}
}
-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 @@
// 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(),