[clang-tidy] Rename hicpp-signed-bitwise to bugprone-signed-bitwise (#190449)
Part of https://github.com/llvm/llvm-project/issues/183462. Closes https://github.com/llvm/llvm-project/issues/183465. --------- Co-authored-by: EugeneZelenko <eugene.zelenko@gmail.com>
This commit is contained in:
@@ -72,6 +72,7 @@
|
||||
#include "ReturnConstRefFromParameterCheck.h"
|
||||
#include "SharedPtrArrayMismatchCheck.h"
|
||||
#include "SignalHandlerCheck.h"
|
||||
#include "SignedBitwiseCheck.h"
|
||||
#include "SignedCharMisuseCheck.h"
|
||||
#include "SizeofContainerCheck.h"
|
||||
#include "SizeofExpressionCheck.h"
|
||||
@@ -247,6 +248,7 @@ public:
|
||||
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>(
|
||||
|
||||
@@ -75,6 +75,7 @@ add_clang_library(clangTidyBugproneModule STATIC
|
||||
ReturnConstRefFromParameterCheck.cpp
|
||||
SharedPtrArrayMismatchCheck.cpp
|
||||
SignalHandlerCheck.cpp
|
||||
SignedBitwiseCheck.cpp
|
||||
SignedCharMisuseCheck.cpp
|
||||
SizeofContainerCheck.cpp
|
||||
SizeofExpressionCheck.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
|
||||
@@ -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 @@ private:
|
||||
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
|
||||
@@ -6,7 +6,6 @@ set(LLVM_LINK_COMPONENTS
|
||||
add_clang_library(clangTidyHICPPModule STATIC
|
||||
HICPPTidyModule.cpp
|
||||
MultiwayPathsCoveredCheck.cpp
|
||||
SignedBitwiseCheck.cpp
|
||||
|
||||
LINK_LIBS
|
||||
clangTidy
|
||||
|
||||
@@ -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 @@ public:
|
||||
"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>(
|
||||
|
||||
@@ -211,6 +211,11 @@ New check aliases
|
||||
<clang-tidy/checks/portability/no-assembler>`. The `hicpp-no-assembler`
|
||||
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.
|
||||
|
||||
- Renamed :doc:`performance-faster-string-find
|
||||
<clang-tidy/checks/performance/faster-string-find>` to
|
||||
:doc:`performance-prefer-single-char-overloads
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
.. 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.
|
||||
|
||||
Performing bitwise operations on signed integers can be confusing and may
|
||||
lead to undefined or implementation dependent behavior. In particular, right
|
||||
shift a signed integer is implementation dependent, while left shift a signed
|
||||
integer may result in undefined behavior.
|
||||
|
||||
.. code-block:: c++
|
||||
|
||||
int main(){
|
||||
int x = -4;
|
||||
int y = x >> 1; // y can be -2 or 2147483646
|
||||
}
|
||||
|
||||
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`.
|
||||
@@ -1,17 +1,11 @@
|
||||
.. 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 `hicpp-signed-bitwise` check is an alias, please see
|
||||
`bugprone-signed-bitwise <../bugprone/signed-bitwise.html>`_ for more
|
||||
information.
|
||||
|
||||
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>`_.
|
||||
|
||||
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`.
|
||||
|
||||
@@ -142,6 +142,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>`,
|
||||
@@ -244,7 +245,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"
|
||||
@@ -618,6 +618,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>`,
|
||||
|
||||
@@ -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.
|
||||
@@ -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 {
|
||||
@@ -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"
|
||||
@@ -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 {
|
||||
Reference in New Issue
Block a user