summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang-tidy-vs/ClangTidy/Resources/ClangTidyChecks.yaml4
-rw-r--r--clang-tidy/misc/CMakeLists.txt1
-rw-r--r--clang-tidy/misc/MiscTidyModule.cpp3
-rw-r--r--clang-tidy/misc/PointerAndIntegralOperationCheck.cpp104
-rw-r--r--clang-tidy/misc/PointerAndIntegralOperationCheck.h35
-rw-r--r--docs/clang-tidy/checks/list.rst1
-rw-r--r--docs/clang-tidy/checks/misc-pointer-and-integral-operation.rst24
-rw-r--r--test/clang-tidy/misc-pointer-and-integral-operation-cxx98.cpp45
-rw-r--r--test/clang-tidy/misc-pointer-and-integral-operation.cpp30
9 files changed, 0 insertions, 247 deletions
diff --git a/clang-tidy-vs/ClangTidy/Resources/ClangTidyChecks.yaml b/clang-tidy-vs/ClangTidy/Resources/ClangTidyChecks.yaml
index fc16d234..d35e81d9 100644
--- a/clang-tidy-vs/ClangTidy/Resources/ClangTidyChecks.yaml
+++ b/clang-tidy-vs/ClangTidy/Resources/ClangTidyChecks.yaml
@@ -239,10 +239,6 @@ Checks:
Description:
Name: misc-non-copyable-objects
- Category: Miscellaneous
- Label: Suspicious pointer / integer operations
- Description:
- Name: misc-pointer-and-integral-operation
- - Category: Miscellaneous
Label: Find redundant expressions
Description:
Name: misc-redundant-expression
diff --git a/clang-tidy/misc/CMakeLists.txt b/clang-tidy/misc/CMakeLists.txt
index 12a8c779..25077725 100644
--- a/clang-tidy/misc/CMakeLists.txt
+++ b/clang-tidy/misc/CMakeLists.txt
@@ -24,7 +24,6 @@ add_clang_library(clangTidyMiscModule
NewDeleteOverloadsCheck.cpp
NoexceptMoveConstructorCheck.cpp
NonCopyableObjects.cpp
- PointerAndIntegralOperationCheck.cpp
RedundantExpressionCheck.cpp
SizeofContainerCheck.cpp
SizeofExpressionCheck.cpp
diff --git a/clang-tidy/misc/MiscTidyModule.cpp b/clang-tidy/misc/MiscTidyModule.cpp
index b952947f..a51f13a5 100644
--- a/clang-tidy/misc/MiscTidyModule.cpp
+++ b/clang-tidy/misc/MiscTidyModule.cpp
@@ -32,7 +32,6 @@
#include "NewDeleteOverloadsCheck.h"
#include "NoexceptMoveConstructorCheck.h"
#include "NonCopyableObjects.h"
-#include "PointerAndIntegralOperationCheck.h"
#include "RedundantExpressionCheck.h"
#include "SizeofContainerCheck.h"
#include "SizeofExpressionCheck.h"
@@ -104,8 +103,6 @@ public:
"misc-noexcept-move-constructor");
CheckFactories.registerCheck<NonCopyableObjectsCheck>(
"misc-non-copyable-objects");
- CheckFactories.registerCheck<PointerAndIntegralOperationCheck>(
- "misc-pointer-and-integral-operation");
CheckFactories.registerCheck<RedundantExpressionCheck>(
"misc-redundant-expression");
CheckFactories.registerCheck<SizeofContainerCheck>("misc-sizeof-container");
diff --git a/clang-tidy/misc/PointerAndIntegralOperationCheck.cpp b/clang-tidy/misc/PointerAndIntegralOperationCheck.cpp
deleted file mode 100644
index f60da78c..00000000
--- a/clang-tidy/misc/PointerAndIntegralOperationCheck.cpp
+++ /dev/null
@@ -1,104 +0,0 @@
-//===--- PointerAndIntegralOperationCheck.cpp - clang-tidy-----------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "PointerAndIntegralOperationCheck.h"
-#include "clang/AST/ASTContext.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "../utils/Matchers.h"
-
-using namespace clang::ast_matchers;
-
-namespace clang {
-namespace tidy {
-namespace misc {
-
-void PointerAndIntegralOperationCheck::registerMatchers(MatchFinder *Finder) {
- const auto PointerExpr = expr(hasType(pointerType()));
- const auto BoolExpr = ignoringParenImpCasts(hasType(booleanType()));
- const auto CharExpr = ignoringParenImpCasts(hasType(isAnyCharacter()));
-
- const auto BinOpWithPointerExpr =
- binaryOperator(unless(anyOf(hasOperatorName(","), hasOperatorName("="))),
- hasEitherOperand(PointerExpr));
-
- const auto AssignToPointerExpr =
- binaryOperator(hasOperatorName("="), hasLHS(PointerExpr));
-
- const auto CompareToPointerExpr =
- binaryOperator(matchers::isRelationalOperator(),
- hasEitherOperand(PointerExpr));
-
- // Detect expression like: ptr = (x != y);
- Finder->addMatcher(binaryOperator(AssignToPointerExpr, hasRHS(BoolExpr))
- .bind("assign-bool-to-pointer"),
- this);
-
- // Detect expression like: ptr = A[i]; where A is char*.
- Finder->addMatcher(binaryOperator(AssignToPointerExpr, hasRHS(CharExpr))
- .bind("assign-char-to-pointer"),
- this);
-
- // Detect expression like: ptr < false;
- Finder->addMatcher(
- binaryOperator(BinOpWithPointerExpr,
- hasEitherOperand(ignoringParenImpCasts(cxxBoolLiteral())))
- .bind("pointer-and-bool-literal"),
- this);
-
- // Detect expression like: ptr < 'a';
- Finder->addMatcher(binaryOperator(BinOpWithPointerExpr,
- hasEitherOperand(ignoringParenImpCasts(
- characterLiteral())))
- .bind("pointer-and-char-literal"),
- this);
-
- // Detect expression like: ptr < 0;
- Finder->addMatcher(binaryOperator(CompareToPointerExpr,
- hasEitherOperand(ignoringParenImpCasts(
- integerLiteral(equals(0)))))
- .bind("compare-pointer-to-zero"),
- this);
-
- // Detect expression like: ptr < nullptr;
- Finder->addMatcher(binaryOperator(CompareToPointerExpr,
- hasEitherOperand(ignoringParenImpCasts(
- cxxNullPtrLiteralExpr())))
- .bind("compare-pointer-to-null"),
- this);
-}
-
-void PointerAndIntegralOperationCheck::check(
- const MatchFinder::MatchResult &Result) {
- if (const auto *E =
- Result.Nodes.getNodeAs<BinaryOperator>("assign-bool-to-pointer")) {
- diag(E->getOperatorLoc(), "suspicious assignment from bool to pointer");
- } else if (const auto *E = Result.Nodes.getNodeAs<BinaryOperator>(
- "assign-char-to-pointer")) {
- diag(E->getOperatorLoc(), "suspicious assignment from char to pointer");
- } else if (const auto *E = Result.Nodes.getNodeAs<BinaryOperator>(
- "pointer-and-bool-literal")) {
- diag(E->getOperatorLoc(),
- "suspicious operation between pointer and bool literal");
- } else if (const auto *E = Result.Nodes.getNodeAs<BinaryOperator>(
- "pointer-and-char-literal")) {
- diag(E->getOperatorLoc(),
- "suspicious operation between pointer and character literal");
- } else if (const auto *E = Result.Nodes.getNodeAs<BinaryOperator>(
- "compare-pointer-to-zero")) {
- diag(E->getOperatorLoc(), "suspicious comparison of pointer with zero");
- } else if (const auto *E = Result.Nodes.getNodeAs<BinaryOperator>(
- "compare-pointer-to-null")) {
- diag(E->getOperatorLoc(),
- "suspicious comparison of pointer with null expression");
- }
-}
-
-} // namespace misc
-} // namespace tidy
-} // namespace clang
diff --git a/clang-tidy/misc/PointerAndIntegralOperationCheck.h b/clang-tidy/misc/PointerAndIntegralOperationCheck.h
deleted file mode 100644
index 996253e8..00000000
--- a/clang-tidy/misc/PointerAndIntegralOperationCheck.h
+++ /dev/null
@@ -1,35 +0,0 @@
-//===--- PointerAndIntegralOperationCheck.h - clang-tidy---------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_POINTER_AND_INTEGRAL_OPERATION_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_POINTER_AND_INTEGRAL_OPERATION_H
-
-#include "../ClangTidy.h"
-
-namespace clang {
-namespace tidy {
-namespace misc {
-
-/// Find suspicious expressions involving pointer and integral types.
-///
-/// For the user-facing documentation see:
-/// http://clang.llvm.org/extra/clang-tidy/checks/misc-pointer-and-integral-operation.html
-class PointerAndIntegralOperationCheck : public ClangTidyCheck {
-public:
- PointerAndIntegralOperationCheck(StringRef Name, ClangTidyContext *Context)
- : ClangTidyCheck(Name, Context) {}
- void registerMatchers(ast_matchers::MatchFinder *Finder) override;
- void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
-};
-
-} // namespace misc
-} // namespace tidy
-} // namespace clang
-
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_POINTER_AND_INTEGRAL_OPERATION_H
diff --git a/docs/clang-tidy/checks/list.rst b/docs/clang-tidy/checks/list.rst
index 33b47b41..ba66c9d1 100644
--- a/docs/clang-tidy/checks/list.rst
+++ b/docs/clang-tidy/checks/list.rst
@@ -74,7 +74,6 @@ Clang-Tidy Checks
misc-new-delete-overloads
misc-noexcept-move-constructor
misc-non-copyable-objects
- misc-pointer-and-integral-operation
misc-redundant-expression
misc-sizeof-container
misc-sizeof-expression
diff --git a/docs/clang-tidy/checks/misc-pointer-and-integral-operation.rst b/docs/clang-tidy/checks/misc-pointer-and-integral-operation.rst
deleted file mode 100644
index 6dce958c..00000000
--- a/docs/clang-tidy/checks/misc-pointer-and-integral-operation.rst
+++ /dev/null
@@ -1,24 +0,0 @@
-.. title:: clang-tidy - misc-pointer-and-integral-operation
-
-misc-pointer-and-integral-operation
-===================================
-
-Looks for operation involving pointers and integral types. A common mistake is
-to forget to dereference a pointer. These errors may be detected when a pointer
-object is compare to an object with integral type.
-
-Examples:
-
-.. code-block:: c++
-
- char* ptr;
- if ((ptr = malloc(...)) < nullptr) // Pointer comparison with operator '<'
- ... // Should probably be '!='
-
- if (ptr == '\0') // Should probably be *ptr
- ...
-
- void Process(std::string path, bool* error) {
- [...]
- if (error != false) // Should probably be *error
- ...
diff --git a/test/clang-tidy/misc-pointer-and-integral-operation-cxx98.cpp b/test/clang-tidy/misc-pointer-and-integral-operation-cxx98.cpp
deleted file mode 100644
index 4834a469..00000000
--- a/test/clang-tidy/misc-pointer-and-integral-operation-cxx98.cpp
+++ /dev/null
@@ -1,45 +0,0 @@
-// RUN: %check_clang_tidy %s misc-pointer-and-integral-operation %t -- -- -std=c++98
-
-bool* pb;
-char* pc;
-int* pi;
-
-int Test() {
- pb = false;
- // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: suspicious assignment from bool to pointer [misc-pointer-and-integral-operation]
- pc = '\0';
- // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: suspicious assignment from char to pointer
-
- pb = (false?false:false);
- // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: suspicious assignment from bool to pointer
- pb = (4 != 5?false:false);
- // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: suspicious assignment from bool to pointer
-
- if (pb < false) return 0;
- // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious operation between pointer and bool literal
- if (pb != false) return 0;
- // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious operation between pointer and bool literal
- if (pc < '\0') return 0;
- // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious operation between pointer and character literal
- if (pc != '\0') return 0;
- // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious operation between pointer and character literal
- if (pi < '\0') return 0;
- // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious operation between pointer and character literal
- if (pi != '\0') return 0;
- // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious operation between pointer and character literal
-
- return 1;
-}
-
-int Valid() {
- *pb = false;
- *pc = '\0';
-
- pb += 0;
- pc += 0;
- pi += 0;
-
- pb += (pb != 0);
- pc += (pc != 0);
- pi += (pi != 0);
-}
diff --git a/test/clang-tidy/misc-pointer-and-integral-operation.cpp b/test/clang-tidy/misc-pointer-and-integral-operation.cpp
deleted file mode 100644
index 6591f0af..00000000
--- a/test/clang-tidy/misc-pointer-and-integral-operation.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-// RUN: %check_clang_tidy %s misc-pointer-and-integral-operation %t
-
-bool* pb;
-char* pc;
-int* pi;
-
-int Test() {
- if (pi < 0) return 0;
- // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious comparison of pointer with zero [misc-pointer-and-integral-operation]
- if (pi <= 0) return 0;
- // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious comparison of pointer with zero
-
- if (nullptr <= pb) return 0;
- // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: suspicious comparison of pointer with null
- if (pc < nullptr) return 0;
- // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious comparison of pointer with null
- if (pi > nullptr) return 0;
- // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious comparison of pointer with null
-
- return 1;
-}
-
-int Valid() {
- *pb = false;
- *pc = '\0';
-
- pi += (pi != nullptr);
- pi -= (pi == nullptr);
- pc += (pb != nullptr);
-}