[PATCH] D122544: Utilize comparison operation implemented in APInt
Danny Mösch via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 28 14:34:45 PDT 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rGff60af91ac0b: [clang-tidy] Utilize comparison operation implemented in APInt (authored by SimplyDanny).
Changed prior to commit:
https://reviews.llvm.org/D122544?vs=418450&id=418709#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D122544/new/
https://reviews.llvm.org/D122544
Files:
clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
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/docs/ReleaseNotes.rst
===================================================================
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -122,6 +122,9 @@
- Fixed a false positive in :doc:`misc-redundant-expression <clang-tidy/checks/misc-redundant-expression>`
involving overloaded comparison operators.
+- Fixed a crash in :doc:`bugprone-sizeof-expression <clang-tidy/checks/bugprone-sizeof-expression>` when
+ `sizeof(...)` is compared agains a `__int128_t`.
+
Removed checks
^^^^^^^^^^^^^^
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.418709.patch
Type: text/x-patch
Size: 1937 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220328/6dfde0f1/attachment-0001.bin>
More information about the cfe-commits
mailing list