[PATCH] D122544: Utilize comparison operation implemented in APInt

Danny Mösch via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 27 07:43:01 PDT 2022


SimplyDanny created this revision.
SimplyDanny added a reviewer: njames93.
Herald added a subscriber: carlosgalvezp.
Herald added a project: All.
SimplyDanny requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

This is a fix for #53963.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122544

Files:
  clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-sizeof-expression.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-sizeof-expression.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-sizeof-expression.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-sizeof-expression.cpp
@@ -172,7 +172,10 @@
 template <typename T>
 int Bar() { T A[5]; return sizeof(A[0]) / sizeof(T); }
 // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)'
-int Test3() { return Foo<42>() + Bar<char>(); }
+template <__int128_t N> 
+bool Baz() { return sizeof(A) < N; }
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: suspicious comparison of 'sizeof(expr)' to a constant
+int Test3() { return Foo<42>() + Bar<char>() + Baz<-1>(); }
 
 static const char* kABC = "abc";
 static const wchar_t* kDEF = L"def";
Index: clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
@@ -20,7 +20,7 @@
 namespace {
 
 AST_MATCHER_P(IntegerLiteral, isBiggerThan, unsigned, N) {
-  return Node.getValue().getZExtValue() > N;
+  return Node.getValue().ugt(N);
 }
 
 AST_MATCHER_P2(Expr, hasSizeOfDescendant, int, Depth,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122544.418450.patch
Type: text/x-patch
Size: 1364 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220327/1f5170e7/attachment.bin>


More information about the cfe-commits mailing list