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

Alexander Kornienko via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 2 05:33:18 PST 2018


Thanks! I knew there was something already, but I hadn't find it ;)

On Fri, Feb 2, 2018 at 2:23 PM, Benjamin Kramer via cfe-commits <
cfe-commits at lists.llvm.org> wrote:

> 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 at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180202/fbe7957e/attachment.html>


More information about the cfe-commits mailing list