https://github.com/heturing updated https://github.com/llvm/llvm-project/pull/190449
>From 2a754d11fb85339ba6e8f25761a65c808d09e97c Mon Sep 17 00:00:00 2001 From: Jiaqi He <[email protected]> Date: Sat, 4 Apr 2026 00:19:00 -0600 Subject: [PATCH] [clang-tidy] Rename hicpp-signed-bitwise to bugprone-signed-bitwise --- .../clang-tidy/bugprone/BugproneTidyModule.cpp | 2 ++ .../clang-tidy/bugprone/CMakeLists.txt | 1 + .../{hicpp => bugprone}/SignedBitwiseCheck.cpp | 4 ++-- .../{hicpp => bugprone}/SignedBitwiseCheck.h | 12 ++++++------ clang-tools-extra/clang-tidy/hicpp/CMakeLists.txt | 1 - .../clang-tidy/hicpp/HICPPTidyModule.cpp | 5 +++-- clang-tools-extra/docs/ReleaseNotes.rst | 5 +++++ .../clang-tidy/checks/bugprone/signed-bitwise.rst | 15 +++++++++++++++ .../clang-tidy/checks/hicpp/signed-bitwise.rst | 9 +++++---- clang-tools-extra/docs/clang-tidy/checks/list.rst | 3 ++- .../checkers/hicpp/signed-bitwise-bug34747.cpp | 2 +- .../hicpp/signed-bitwise-integer-literals.cpp | 6 +++--- .../hicpp/signed-bitwise-standard-types.cpp | 2 +- .../clang-tidy/checkers/hicpp/signed-bitwise.cpp | 2 +- 14 files changed, 47 insertions(+), 22 deletions(-) rename clang-tools-extra/clang-tidy/{hicpp => bugprone}/SignedBitwiseCheck.cpp (98%) rename clang-tools-extra/clang-tidy/{hicpp => bugprone}/SignedBitwiseCheck.h (72%) create mode 100644 clang-tools-extra/docs/clang-tidy/checks/bugprone/signed-bitwise.rst diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp index b39aea62a9546..e06b6c530dc86 100644 --- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp @@ -71,6 +71,7 @@ #include "ReturnConstRefFromParameterCheck.h" #include "SharedPtrArrayMismatchCheck.h" #include "SignalHandlerCheck.h" +#include "SignedBitwiseCheck.h" #include "SignedCharMisuseCheck.h" #include "SizeofContainerCheck.h" #include "SizeofExpressionCheck.h" @@ -244,6 +245,7 @@ class BugproneModule : public ClangTidyModule { CheckFactories.registerCheck<SharedPtrArrayMismatchCheck>( "bugprone-shared-ptr-array-mismatch"); CheckFactories.registerCheck<SignalHandlerCheck>("bugprone-signal-handler"); + CheckFactories.registerCheck<SignedBitwiseCheck>("bugprone-signed-bitwise"); CheckFactories.registerCheck<SignedCharMisuseCheck>( "bugprone-signed-char-misuse"); CheckFactories.registerCheck<SizeofContainerCheck>( diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt index f7f185d53b269..248641828b1f6 100644 --- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt @@ -74,6 +74,7 @@ add_clang_library(clangTidyBugproneModule STATIC ReturnConstRefFromParameterCheck.cpp SharedPtrArrayMismatchCheck.cpp SignalHandlerCheck.cpp + SignedBitwiseCheck.cpp SignedCharMisuseCheck.cpp SizeofContainerCheck.cpp SizeofExpressionCheck.cpp diff --git a/clang-tools-extra/clang-tidy/hicpp/SignedBitwiseCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SignedBitwiseCheck.cpp similarity index 98% rename from clang-tools-extra/clang-tidy/hicpp/SignedBitwiseCheck.cpp rename to clang-tools-extra/clang-tidy/bugprone/SignedBitwiseCheck.cpp index 19c716e941271..5a3a82af24c98 100644 --- a/clang-tools-extra/clang-tidy/hicpp/SignedBitwiseCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/SignedBitwiseCheck.cpp @@ -14,7 +14,7 @@ using namespace clang::ast_matchers; using namespace clang::ast_matchers::internal; -namespace clang::tidy::hicpp { +namespace clang::tidy::bugprone { SignedBitwiseCheck::SignedBitwiseCheck(StringRef Name, ClangTidyContext *Context) @@ -99,4 +99,4 @@ void SignedBitwiseCheck::check(const MatchFinder::MatchResult &Result) { << IsUnary << SignedOperand->getSourceRange() << OperatorLoc; } -} // namespace clang::tidy::hicpp +} // namespace clang::tidy::bugprone diff --git a/clang-tools-extra/clang-tidy/hicpp/SignedBitwiseCheck.h b/clang-tools-extra/clang-tidy/bugprone/SignedBitwiseCheck.h similarity index 72% rename from clang-tools-extra/clang-tidy/hicpp/SignedBitwiseCheck.h rename to clang-tools-extra/clang-tidy/bugprone/SignedBitwiseCheck.h index ef92a4d13f43e..d5293248f5595 100644 --- a/clang-tools-extra/clang-tidy/hicpp/SignedBitwiseCheck.h +++ b/clang-tools-extra/clang-tidy/bugprone/SignedBitwiseCheck.h @@ -6,18 +6,18 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_SIGNEDBITWISECHECK_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_SIGNEDBITWISECHECK_H +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SIGNEDBITWISECHECK_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SIGNEDBITWISECHECK_H #include "../ClangTidyCheck.h" -namespace clang::tidy::hicpp { +namespace clang::tidy::bugprone { /// This check implements the rule 5.6.1 of the HICPP Standard, which disallows /// bitwise operations on signed integer types. /// /// For the user-facing documentation see: -/// https://clang.llvm.org/extra/clang-tidy/checks/hicpp/signed-bitwise.html +/// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/signed-bitwise.html class SignedBitwiseCheck : public ClangTidyCheck { public: SignedBitwiseCheck(StringRef Name, ClangTidyContext *Context); @@ -29,6 +29,6 @@ class SignedBitwiseCheck : public ClangTidyCheck { bool IgnorePositiveIntegerLiterals; }; -} // namespace clang::tidy::hicpp +} // namespace clang::tidy::bugprone -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_SIGNEDBITWISECHECK_H +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SIGNEDBITWISECHECK_H diff --git a/clang-tools-extra/clang-tidy/hicpp/CMakeLists.txt b/clang-tools-extra/clang-tidy/hicpp/CMakeLists.txt index b5bcbf389b4ae..b9b7e716d00a4 100644 --- a/clang-tools-extra/clang-tidy/hicpp/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/hicpp/CMakeLists.txt @@ -6,7 +6,6 @@ set(LLVM_LINK_COMPONENTS add_clang_library(clangTidyHICPPModule STATIC HICPPTidyModule.cpp MultiwayPathsCoveredCheck.cpp - SignedBitwiseCheck.cpp LINK_LIBS clangTidy diff --git a/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp b/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp index 38d9235878e62..501e7fc0e2d9b 100644 --- a/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp @@ -8,6 +8,7 @@ #include "../ClangTidy.h" #include "../ClangTidyModule.h" +#include "../bugprone/SignedBitwiseCheck.h" #include "../bugprone/StdExceptionBaseclassCheck.h" #include "../bugprone/UndelegatedConstructorCheck.h" #include "../bugprone/UnusedReturnValueCheck.h" @@ -38,7 +39,6 @@ #include "../readability/NamedParameterCheck.h" #include "../readability/UppercaseLiteralSuffixCheck.h" #include "MultiwayPathsCoveredCheck.h" -#include "SignedBitwiseCheck.h" namespace clang::tidy { namespace hicpp { @@ -61,7 +61,8 @@ class HICPPModule : public ClangTidyModule { "hicpp-ignored-remove-result"); CheckFactories.registerCheck<MultiwayPathsCoveredCheck>( "hicpp-multiway-paths-covered"); - CheckFactories.registerCheck<SignedBitwiseCheck>("hicpp-signed-bitwise"); + CheckFactories.registerCheck<bugprone::SignedBitwiseCheck>( + "hicpp-signed-bitwise"); CheckFactories.registerCheck<google::ExplicitConstructorCheck>( "hicpp-explicit-conversions"); CheckFactories.registerCheck<readability::FunctionSizeCheck>( diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 36e311341f336..4ac1091170208 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -200,6 +200,11 @@ New check aliases :doc:`performance-prefer-single-char-overloads <clang-tidy/checks/performance/prefer-single-char-overloads>`. The `performance-faster-string-find` name is kept as an alias. + +- Renamed :doc:`hicpp-signed-bitwise <clang-tidy/checks/hicpp/signed-bitwise>` + to :doc:`bugprone-signed-bitwise + <clang-tidy/checks/bugprone/signed-bitwise>`. The `hicpp-signed-bitwise` + name is kept as an alias. Changes in existing checks ^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/signed-bitwise.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/signed-bitwise.rst new file mode 100644 index 0000000000000..43264208d37f0 --- /dev/null +++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/signed-bitwise.rst @@ -0,0 +1,15 @@ +.. title:: clang-tidy - bugprone-signed-bitwise + +bugprone-signed-bitwise +======================= + +Finds uses of bitwise operations on signed integer types, which may lead to +undefined or implementation defined behavior. + +Options +------- + +.. option:: IgnorePositiveIntegerLiterals + + If this option is set to `true`, the check will not warn on bitwise operations with positive integer literals, e.g. `~0`, `2 << 1`, etc. + Default value is `false`. diff --git a/clang-tools-extra/docs/clang-tidy/checks/hicpp/signed-bitwise.rst b/clang-tools-extra/docs/clang-tidy/checks/hicpp/signed-bitwise.rst index 0461f0cd61911..969373b3c2290 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/hicpp/signed-bitwise.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/hicpp/signed-bitwise.rst @@ -1,12 +1,13 @@ .. title:: clang-tidy - hicpp-signed-bitwise +.. meta:: + :http-equiv=refresh: 5;URL=../bugprone/signed-bitwise.html hicpp-signed-bitwise ==================== -Finds uses of bitwise operations on signed integer types, which may lead to -undefined or implementation defined behavior. - -The according rule is defined in the `High Integrity C++ Standard, Section 5.6.1 <https://www.perforce.com/resources/qac/high-integrity-cpp-coding-rules>`_. +The `hicpp-signed-bitwise` check is an alias, please see +`bugprone-signed-bitwise <../bugprone/signed-bitwise.html>`_ for more +information. Options ------- diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst index 2b5be931271ec..f0838cbfb9b1e 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/list.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst @@ -141,6 +141,7 @@ Clang-Tidy Checks :doc:`bugprone-return-const-ref-from-parameter <bugprone/return-const-ref-from-parameter>`, :doc:`bugprone-shared-ptr-array-mismatch <bugprone/shared-ptr-array-mismatch>`, "Yes" :doc:`bugprone-signal-handler <bugprone/signal-handler>`, + :doc:`bugprone-signed-bitwise <bugprone/signed-bitwise>`, :doc:`bugprone-signed-char-misuse <bugprone/signed-char-misuse>`, :doc:`bugprone-sizeof-container <bugprone/sizeof-container>`, :doc:`bugprone-sizeof-expression <bugprone/sizeof-expression>`, @@ -243,7 +244,6 @@ Clang-Tidy Checks :doc:`google-upgrade-googletest-case <google/upgrade-googletest-case>`, "Yes" :doc:`hicpp-exception-baseclass <hicpp/exception-baseclass>`, :doc:`hicpp-multiway-paths-covered <hicpp/multiway-paths-covered>`, - :doc:`hicpp-signed-bitwise <hicpp/signed-bitwise>`, :doc:`linuxkernel-must-check-errs <linuxkernel/must-check-errs>`, :doc:`llvm-header-guard <llvm/header-guard>`, :doc:`llvm-include-order <llvm/include-order>`, "Yes" @@ -616,6 +616,7 @@ Check aliases :doc:`hicpp-no-assembler <hicpp/no-assembler>`, :doc:`portability-no-assembler <portability/no-assembler>`, :doc:`hicpp-no-malloc <hicpp/no-malloc>`, :doc:`cppcoreguidelines-no-malloc <cppcoreguidelines/no-malloc>`, :doc:`hicpp-noexcept-move <hicpp/noexcept-move>`, :doc:`performance-noexcept-move-constructor <performance/noexcept-move-constructor>`, "Yes" + :doc:`hicpp-signed-bitwise <hicpp/signed-bitwise>`, :doc:`bugprone-signed-bitwise <bugprone/signed-bitwise>`, :doc:`hicpp-special-member-functions <hicpp/special-member-functions>`, :doc:`cppcoreguidelines-special-member-functions <cppcoreguidelines/special-member-functions>`, :doc:`hicpp-static-assert <hicpp/static-assert>`, :doc:`misc-static-assert <misc/static-assert>`, "Yes" :doc:`hicpp-undelegated-constructor <hicpp/undelegated-constructor>`, :doc:`bugprone-undelegated-constructor <bugprone/undelegated-constructor>`, diff --git a/clang-tools-extra/test/clang-tidy/checkers/hicpp/signed-bitwise-bug34747.cpp b/clang-tools-extra/test/clang-tidy/checkers/hicpp/signed-bitwise-bug34747.cpp index 1502b809e6188..cbd8787409453 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/hicpp/signed-bitwise-bug34747.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/hicpp/signed-bitwise-bug34747.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy %s hicpp-signed-bitwise %t -- +// RUN: %check_clang_tidy %s bugprone-signed-bitwise %t -- // Note: this test expects no diagnostics, but FileCheck cannot handle that, // hence the use of | count 0. diff --git a/clang-tools-extra/test/clang-tidy/checkers/hicpp/signed-bitwise-integer-literals.cpp b/clang-tools-extra/test/clang-tidy/checkers/hicpp/signed-bitwise-integer-literals.cpp index 509988875c3d5..009d8bdd812f1 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/hicpp/signed-bitwise-integer-literals.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/hicpp/signed-bitwise-integer-literals.cpp @@ -1,5 +1,5 @@ -// RUN: %check_clang_tidy -std=c++11-or-later %s hicpp-signed-bitwise %t -- \ -// RUN: -config="{CheckOptions: {hicpp-signed-bitwise.IgnorePositiveIntegerLiterals: true}}" +// RUN: %check_clang_tidy -std=c++11-or-later %s bugprone-signed-bitwise %t -- \ +// RUN: -config="{CheckOptions: {bugprone-signed-bitwise.IgnorePositiveIntegerLiterals: true}}" void examples() { unsigned UValue = 40u; @@ -22,7 +22,7 @@ void examples() { // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator IResult = ~0; //Ok IResult = -1 & 1; - // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator [hicpp-signed-bitwise] + // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator [bugprone-signed-bitwise] } enum EnumConstruction { diff --git a/clang-tools-extra/test/clang-tidy/checkers/hicpp/signed-bitwise-standard-types.cpp b/clang-tools-extra/test/clang-tidy/checkers/hicpp/signed-bitwise-standard-types.cpp index a2fe5835e0149..875aad545e76d 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/hicpp/signed-bitwise-standard-types.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/hicpp/signed-bitwise-standard-types.cpp @@ -1,4 +1,4 @@ -// RUN: clang-tidy %s -checks='-*,hicpp-signed-bitwise' -- -std=c++11 +// RUN: clang-tidy %s -checks='-*,bugprone-signed-bitwise' -- -std=c++11 // FIXME: Make the test work in all language modes. #include "signed-bitwise-standard-types.h" diff --git a/clang-tools-extra/test/clang-tidy/checkers/hicpp/signed-bitwise.cpp b/clang-tools-extra/test/clang-tidy/checkers/hicpp/signed-bitwise.cpp index bea9366ea5a30..d267129e032ec 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/hicpp/signed-bitwise.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/hicpp/signed-bitwise.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy %s hicpp-signed-bitwise %t -- -- --target=x86_64-linux +// RUN: %check_clang_tidy %s bugprone-signed-bitwise %t -- -- --target=x86_64-linux // These could cause false positives and should not be considered. struct StreamClass { _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
