Author: Danny Mösch Date: 2022-03-28T23:32:58+02:00 New Revision: ff60af91ac0bbab12dd5ff5dc9b78bc1636f2d86
URL: https://github.com/llvm/llvm-project/commit/ff60af91ac0bbab12dd5ff5dc9b78bc1636f2d86 DIFF: https://github.com/llvm/llvm-project/commit/ff60af91ac0bbab12dd5ff5dc9b78bc1636f2d86.diff LOG: [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 Added: Modified: 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 Removed: ################################################################################ diff --git a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp index 5bdf01c098dc6..4c537afd3347b 100644 --- a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp @@ -20,7 +20,7 @@ namespace bugprone { 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, diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 2d144aae75e65..729bb3bbd7365 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -122,6 +122,9 @@ Changes in existing checks - 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 ^^^^^^^^^^^^^^ diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone-sizeof-expression.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone-sizeof-expression.cpp index 21d4532294aaf..605243cf7a782 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone-sizeof-expression.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone-sizeof-expression.cpp @@ -172,7 +172,10 @@ int Foo() { int A[T]; return sizeof(T); } 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"; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits