2013-07-29 16:19:24 +08:00
|
|
|
//===--- LLVMTidyModule.cpp - clang-tidy ----------------------------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2013-07-29 16:19:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "../ClangTidy.h"
|
|
|
|
#include "../ClangTidyModule.h"
|
|
|
|
#include "../ClangTidyModuleRegistry.h"
|
2015-01-14 19:24:38 +08:00
|
|
|
#include "../readability/NamespaceCommentCheck.h"
|
2020-01-15 03:05:45 +08:00
|
|
|
#include "../readability/QualifiedAutoCheck.h"
|
2014-08-13 21:57:57 +08:00
|
|
|
#include "HeaderGuardCheck.h"
|
2014-05-20 00:39:08 +08:00
|
|
|
#include "IncludeOrderCheck.h"
|
[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
2019-04-25 05:25:57 +08:00
|
|
|
#include "PreferIsaOrDynCastInConditionalsCheck.h"
|
[clang-tidy] Add llvm-prefer-register-over-unsigned to clang-tidy
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).
Reviewers: arsenm, bogner
Subscribers: jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, mgorny, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, cfe-commits, llvm-commits
Tags: #clang, #llvm
Differential Revision: https://reviews.llvm.org/D65919
llvm-svn: 370512
2019-08-31 04:01:59 +08:00
|
|
|
#include "PreferRegisterOverUnsignedCheck.h"
|
2014-07-08 22:32:17 +08:00
|
|
|
#include "TwineLocalCheck.h"
|
2013-07-29 16:19:24 +08:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace tidy {
|
2019-05-11 02:27:09 +08:00
|
|
|
namespace llvm_check {
|
2013-07-29 16:19:24 +08:00
|
|
|
|
|
|
|
class LLVMModule : public ClangTidyModule {
|
|
|
|
public:
|
2014-03-05 21:01:24 +08:00
|
|
|
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
|
2014-09-10 19:06:43 +08:00
|
|
|
CheckFactories.registerCheck<LLVMHeaderGuardCheck>("llvm-header-guard");
|
|
|
|
CheckFactories.registerCheck<IncludeOrderCheck>("llvm-include-order");
|
2014-09-22 18:41:39 +08:00
|
|
|
CheckFactories.registerCheck<readability::NamespaceCommentCheck>(
|
2014-09-10 19:06:43 +08:00
|
|
|
"llvm-namespace-comment");
|
[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
2019-04-25 05:25:57 +08:00
|
|
|
CheckFactories.registerCheck<PreferIsaOrDynCastInConditionalsCheck>(
|
|
|
|
"llvm-prefer-isa-or-dyn-cast-in-conditionals");
|
[clang-tidy] Add llvm-prefer-register-over-unsigned to clang-tidy
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).
Reviewers: arsenm, bogner
Subscribers: jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, mgorny, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, cfe-commits, llvm-commits
Tags: #clang, #llvm
Differential Revision: https://reviews.llvm.org/D65919
llvm-svn: 370512
2019-08-31 04:01:59 +08:00
|
|
|
CheckFactories.registerCheck<PreferRegisterOverUnsignedCheck>(
|
|
|
|
"llvm-prefer-register-over-unsigned");
|
2020-01-15 03:05:45 +08:00
|
|
|
CheckFactories.registerCheck<readability::QualifiedAutoCheck>(
|
|
|
|
"llvm-qualified-auto");
|
2014-09-10 19:06:43 +08:00
|
|
|
CheckFactories.registerCheck<TwineLocalCheck>("llvm-twine-local");
|
2013-07-29 16:19:24 +08:00
|
|
|
}
|
2020-02-03 05:27:04 +08:00
|
|
|
|
|
|
|
ClangTidyOptions getModuleOptions() override {
|
|
|
|
ClangTidyOptions Options;
|
|
|
|
Options.CheckOptions["llvm-qualified-auto.AddConstToQualified"] = "0";
|
|
|
|
return Options;
|
|
|
|
}
|
2013-07-29 16:19:24 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Register the LLVMTidyModule using this statically initialized variable.
|
|
|
|
static ClangTidyModuleRegistry::Add<LLVMModule> X("llvm-module",
|
|
|
|
"Adds LLVM lint checks.");
|
|
|
|
|
2019-05-11 02:27:09 +08:00
|
|
|
} // namespace llvm_check
|
2015-03-02 20:39:18 +08:00
|
|
|
|
2013-07-29 16:19:24 +08:00
|
|
|
// This anchor is used to force the linker to link in the generated object file
|
|
|
|
// and thus register the LLVMModule.
|
|
|
|
volatile int LLVMModuleAnchorSource = 0;
|
|
|
|
|
|
|
|
} // namespace tidy
|
|
|
|
} // namespace clang
|