Skip to content

Commit ff60af9

Browse files
committed
[clang-tidy] Utilize comparison operation implemented in APInt
This is a fix for #53963. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D122544
1 parent eee536d commit ff60af9

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace bugprone {
2020
namespace {
2121

2222
AST_MATCHER_P(IntegerLiteral, isBiggerThan, unsigned, N) {
23-
return Node.getValue().getZExtValue() > N;
23+
return Node.getValue().ugt(N);
2424
}
2525

2626
AST_MATCHER_P2(Expr, hasSizeOfDescendant, int, Depth,

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ Changes in existing checks
122122
- Fixed a false positive in :doc:`misc-redundant-expression <clang-tidy/checks/misc-redundant-expression>`
123123
involving overloaded comparison operators.
124124

125+
- Fixed a crash in :doc:`bugprone-sizeof-expression <clang-tidy/checks/bugprone-sizeof-expression>` when
126+
`sizeof(...)` is compared agains a `__int128_t`.
127+
125128
Removed checks
126129
^^^^^^^^^^^^^^
127130

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,10 @@ int Foo() { int A[T]; return sizeof(T); }
172172
template <typename T>
173173
int Bar() { T A[5]; return sizeof(A[0]) / sizeof(T); }
174174
// CHECK-MESSAGES: :[[@LINE-1]]:28: warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)'
175-
int Test3() { return Foo<42>() + Bar<char>(); }
175+
template <__int128_t N>
176+
bool Baz() { return sizeof(A) < N; }
177+
// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: suspicious comparison of 'sizeof(expr)' to a constant
178+
int Test3() { return Foo<42>() + Bar<char>() + Baz<-1>(); }
176179

177180
static const char* kABC = "abc";
178181
static const wchar_t* kDEF = L"def";

0 commit comments

Comments
 (0)