[PATCH] D93822: [clang-tidy] Add check for implicit widening of multiplication result
Roman Lebedev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 1 09:55:04 PDT 2021
lebedev.ri marked an inline comment as done.
lebedev.ri added a comment.
In D93822#2664157 <https://reviews.llvm.org/D93822#2664157>, @aaron.ballman wrote:
> The CI is showing build failures and there are some clang-tidy nits to be addressed as well.
Thank you for taking a look!
================
Comment at: clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp:32
+ if (!BO || BO->getOpcode() != BO_Mul)
+ // FIXME: what about: long r = int(x) + (int(y) * int(z)); ?
+ return nullptr;
----------------
aaron.ballman wrote:
> I think that could be handled in a follow-up if we find the need, WDYT?
Sure.
================
Comment at: clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp:75
+ else if (Ty->isSignedIntegerType()) {
+ assert(ETy->isUnsignedIntegerType() &&
+ "Expected source type to be signed.");
----------------
aaron.ballman wrote:
> Might be worth it to have tests around `signed char`, `unsigned char`, and `char` explicitly, as that gets awkward.
Are you asking for test coverage, or for explicit handling of those types?
I'll add tests.
================
Comment at: clang/lib/AST/ASTContext.cpp:10158
+ if (const auto *ETy = T->getAs<EnumType>())
+ T = ETy->getDecl()->getIntegerType();
+
----------------
aaron.ballman wrote:
> This looks to be getting the same value as in the `getCorrespondingUnsignedType()` call?
Yep. Are both of them incorrect?
I'm not sure what should be returned here.
================
Comment at: clang/lib/AST/ASTContext.cpp:10204
+ return SatLongFractTy;
+ default:
+ llvm_unreachable("Unexpected unsigned integer or fixed point type");
----------------
aaron.ballman wrote:
> It looks like `_ExtInt` is missing from both this function and the corresponding unsigned one.
Likewise, i'm not sure what should be returned for that.
Just the original `_ExtInt`?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D93822/new/
https://reviews.llvm.org/D93822
More information about the cfe-commits
mailing list