summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp
diff options
context:
space:
mode:
authorDon Hinton <hintonda@gmail.com>2019-04-24 21:25:57 +0000
committerDon Hinton <hintonda@gmail.com>2019-04-24 21:25:57 +0000
commit28413dd87aa21c72ab4d3e3f686647999eb59903 (patch)
treefd1bf161a117977083606ab6324221f43fc7aba7 /clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp
parentc95c08baa1afb3b654bd756edfaac1c0a063fed9 (diff)
downloadbcm5719-llvm-28413dd87aa21c72ab4d3e3f686647999eb59903.tar.gz
bcm5719-llvm-28413dd87aa21c72ab4d3e3f686647999eb59903.zip
[clang-tidy] Add new checker: llvm-prefer-isa-or-dyn-cast-in-conditionals
Summary: Looks at conditionals and finds cases of ``cast<>``, which will assert rather than return a null pointer, and ``dyn_cast<>`` where the return value is not captured. Additionally, finds cases that match the pattern ``var.foo() && isa<X>(var.foo())``, where the method is called twice and could be expensive. .. code-block:: c++ // Finds cases like these: if (auto x = cast<X>(y)) <...> if (cast<X>(y)) <...> // But not cases like these: if (auto f = cast<Z>(y)->foo()) <...> if (cast<Z>(y)->foo()) <...> Reviewers: alexfh, rjmccall, hokein, aaron.ballman, JonasToth Reviewed By: aaron.ballman Subscribers: xbolva00, Eugene.Zelenko, mgorny, xazax.hun, cfe-commits Tags: #clang-tools-extra, #clang Differential Revision: https://reviews.llvm.org/D59802 llvm-svn: 359142
Diffstat (limited to 'clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp b/clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp
index f5242685c06..fb7b52a3815 100644
--- a/clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp
@@ -12,6 +12,7 @@
#include "../readability/NamespaceCommentCheck.h"
#include "HeaderGuardCheck.h"
#include "IncludeOrderCheck.h"
+#include "PreferIsaOrDynCastInConditionalsCheck.h"
#include "TwineLocalCheck.h"
namespace clang {
@@ -25,6 +26,8 @@ public:
CheckFactories.registerCheck<IncludeOrderCheck>("llvm-include-order");
CheckFactories.registerCheck<readability::NamespaceCommentCheck>(
"llvm-namespace-comment");
+ CheckFactories.registerCheck<PreferIsaOrDynCastInConditionalsCheck>(
+ "llvm-prefer-isa-or-dyn-cast-in-conditionals");
CheckFactories.registerCheck<TwineLocalCheck>("llvm-twine-local");
}
};
OpenPOWER on IntegriCloud