Author: d0k Date: Fri Feb 2 05:23:21 2018 New Revision: 324079 URL: http://llvm.org/viewvc/llvm-project?rev=324079&view=rev Log: [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. Modified: clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp Modified: clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp?rev=324079&r1=324078&r2=324079&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp Fri Feb 2 05:23:21 2018 @@ -966,13 +966,6 @@ void RedundantExpressionCheck::checkRela } } -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(con // 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(), _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits