[PATCH] D35932: [clang-tidy] Add integer division check

Reka Kovacs via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 28 02:20:08 PDT 2017


rnkovacs added a comment.

I run the check on LLVM-Clang, and got this one hit:

  /home/reka/codechecker_dev_env/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp:1000:43: warning: integer division; possible precision loss [bugprone-integer-division]
    SDValue TWOHW = DAG.getConstantFP(1 << (BW / 2), DL, Op.getValueType());
                                            ^

It warns because `getConstantFP()` expects a floating-point value as its first argument. Still seems to be a false positive. I might want to add an exception for bitshift operators.



================
Comment at: docs/clang-tidy/checks/bugprone-integer-division.rst:21-24
+  // Do not warn, there are signs of deliberateness.
+  sin(abs(3) / 5);
+  sin(1 + abs(1 + 7 / 2));
+  1 << 2 / 3;
----------------
alexfh wrote:
> I'd argue that the presence of `abs` here doesn't add any signal, since the function has overloads both for integer and floating point types.
Well, I meant specifically the above declared function, but you're right, the naming was misleading, so I changed that.

To be honest, this check doesn't work for most of the std math functions involving template magic. Custom user-defined functions could be mainly targeted.


https://reviews.llvm.org/D35932





More information about the cfe-commits mailing list