[PATCH] D155457: [clang] Skip tautological comparison if the comparison involves the 'size_t' type
Shivam Gupta via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 17 06:30:29 PDT 2023
xgupta created this revision.
xgupta added reviewers: aaron.ballman, xbolva00.
Herald added a project: All.
xgupta requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
The issue with size_t comes when we are trying to addd
-Wtype-limits to -Wextra for GCC compatibility in review
https://reviews.llvm.org/D142826.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D155457
Files:
clang/lib/Sema/SemaChecking.cpp
Index: clang/lib/Sema/SemaChecking.cpp
===================================================================
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -13363,6 +13363,13 @@
if (InRange && IsEnumConstOrFromMacro(S, Constant))
return false;
+ // Don't warn if the comparison involves the 'size_t' type.
+ QualType SizeT = S.Context.getSizeType();
+ if (S.Context.hasSameType(Constant->getType().getCanonicalType(), SizeT) &&
+ S.Context.hasSameType(Other->getType().getCanonicalType(), SizeT)) {
+ return false;
+ }
+
// A comparison of an unsigned bit-field against 0 is really a type problem,
// even though at the type level the bit-field might promote to 'signed int'.
if (Other->refersToBitField() && InRange && Value == 0 &&
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155457.540991.patch
Type: text/x-patch
Size: 791 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230717/fef260ad/attachment.bin>
More information about the cfe-commits
mailing list