From 28413dd87aa21c72ab4d3e3f686647999eb59903 Mon Sep 17 00:00:00 2001 From: Don Hinton Date: Wed, 24 Apr 2019 21:25:57 +0000 Subject: [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(var.foo())``, where the method is called twice and could be expensive. .. code-block:: c++ // Finds cases like these: if (auto x = cast(y)) <...> if (cast(y)) <...> // But not cases like these: if (auto f = cast(y)->foo()) <...> if (cast(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 --- clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp') 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("llvm-include-order"); CheckFactories.registerCheck( "llvm-namespace-comment"); + CheckFactories.registerCheck( + "llvm-prefer-isa-or-dyn-cast-in-conditionals"); CheckFactories.registerCheck("llvm-twine-local"); } }; -- cgit v1.2.3