[PATCH] D158338: [clang-tidy] [bugprone-implicit-widenin g-of-multiplication-result]Improved check to ignore false positives with integer literals.

Félix-Antoine Constantin via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Aug 19 12:46:58 PDT 2023


felix642 added a comment.

Hi @PiotrZSL thank you for taking the time to look at this revision.

I agree with you we should not silence a warning if no other tool can diagnose the issue.  I'm guessing that -Winteger-overflow does no trigger any warning on unsigned "overflow" since behavior is well defined in the standard :

> 46. This implies that unsigned arithmetic does not overflow because a result that cannot be represented by the resulting unsigned integer type is reduced modulo the number that is one greater than the largest value that can be represented by the resulting unsigned integer type.

But on the other hand I have to agree with DenisYaroshevskiy that it is tedious to add a cast to every multiplication of integer literals on a large codebase. Especially when we know that those values do not overflow.

Maybe we should add some basic calculations when the operation is composed of integer literals, like you previously mentioned, to check if the operation actually overflows and print this warning if it does? 
In that case we could also improve the fix-it and suggest to add LU or U instead of static_cast.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158338/new/

https://reviews.llvm.org/D158338



More information about the cfe-commits mailing list