[PATCH] D155457: [clang] Skip tautological comparison if the comparison involves the 'size_t' type
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 26 10:16:56 PDT 2023
aaron.ballman added a comment.
In D155457#4526168 <https://reviews.llvm.org/D155457#4526168>, @xgupta wrote:
> In D155457#4523388 <https://reviews.llvm.org/D155457#4523388>, @cor3ntin wrote:
>
>> I'm not sure I understand the motivation for this change. Sure, people do that but they also might do the same thing for ssize_t, intmax_t, or to compare int to int32_t.
>> I think a better heuristic would be to not emit a warning for any integral (and floating point?) type that have the same canonical types (but we probably still want one if their non-canonical type if the same)
>
> I am not sure but are you expecting these changes -
>
> // Don't warn if the comparison involves integral or floating-point types with the same canonical types.
> QualType LHSCanonical = Constant->getType().getCanonicalType();
> QualType RHSCanonical = Other->getType().getCanonicalType();
> if ((LHSCanonical->isIntegralOrEnumerationType() || LHSCanonical->isFloatingType()) &&
> S.Context.hasSameType(LHSCanonical, RHSCanonical)) {
> return false;
> }
>
> This will silence a lot of warnings and a total 5 test case fails.
Can you share some examples of what test cases start failing with that approach? What you have above matches what I think @cor3ntin was asking for and does seem like a pretty reasonable way to silence false positives.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D155457/new/
https://reviews.llvm.org/D155457
More information about the cfe-commits
mailing list