diff options
Diffstat (limited to 'clang-tools-extra/clang-tidy')
11 files changed, 52 insertions, 52 deletions
diff --git a/clang-tools-extra/clang-tidy/hicpp/CMakeLists.txt b/clang-tools-extra/clang-tidy/hicpp/CMakeLists.txt index 7752dce1e59..0e37b3e4191 100644 --- a/clang-tools-extra/clang-tidy/hicpp/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/hicpp/CMakeLists.txt @@ -17,6 +17,7 @@ add_clang_library(clangTidyHICPPModule clangTidyGoogleModule clangTidyMiscModule clangTidyModernizeModule + clangTidyPerformanceModule clangTidyReadabilityModule clangTidyUtils ) diff --git a/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp b/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp index 4a60ebd20a5..3b08acbd6bd 100644 --- a/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp @@ -18,9 +18,7 @@ #include "../cppcoreguidelines/SpecialMemberFunctionsCheck.h" #include "../google/DefaultArgumentsCheck.h" #include "../google/ExplicitConstructorCheck.h" -#include "../misc/MoveConstantArgumentCheck.h" #include "../misc/NewDeleteOverloadsCheck.h" -#include "../misc/NoexceptMoveConstructorCheck.h" #include "../misc/StaticAssertCheck.h" #include "../misc/UndelegatedConstructor.h" #include "../modernize/DeprecatedHeadersCheck.h" @@ -31,6 +29,8 @@ #include "../modernize/UseNoexceptCheck.h" #include "../modernize/UseNullptrCheck.h" #include "../modernize/UseOverrideCheck.h" +#include "../performance/MoveConstArgCheck.h" +#include "../performance/NoexceptMoveConstructorCheck.h" #include "../readability/BracesAroundStatementsCheck.h" #include "../readability/FunctionSizeCheck.h" #include "../readability/IdentifierNamingCheck.h" @@ -63,11 +63,11 @@ public: "hicpp-invalid-access-moved"); CheckFactories.registerCheck<cppcoreguidelines::ProTypeMemberInitCheck>( "hicpp-member-init"); - CheckFactories.registerCheck<misc::MoveConstantArgumentCheck>( + CheckFactories.registerCheck<performance::MoveConstArgCheck>( "hicpp-move-const-arg"); CheckFactories.registerCheck<misc::NewDeleteOverloadsCheck>( "hicpp-new-delete-operators"); - CheckFactories.registerCheck<misc::NoexceptMoveConstructorCheck>( + CheckFactories.registerCheck<performance::NoexceptMoveConstructorCheck>( "hicpp-noexcept-move"); CheckFactories .registerCheck<cppcoreguidelines::ProBoundsArrayToPointerDecayCheck>( diff --git a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt index 8e7391ea851..44ea9112ca3 100644 --- a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt @@ -11,9 +11,7 @@ add_clang_library(clangTidyMiscModule MacroRepeatedSideEffectsCheck.cpp MiscTidyModule.cpp MisplacedWideningCastCheck.cpp - MoveConstantArgumentCheck.cpp NewDeleteOverloadsCheck.cpp - NoexceptMoveConstructorCheck.cpp NonCopyableObjects.cpp RedundantExpressionCheck.cpp SizeofContainerCheck.cpp diff --git a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp index b38feca72cd..cae52b98330 100644 --- a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp @@ -18,9 +18,7 @@ #include "MacroRepeatedSideEffectsCheck.h" #include "MisplacedConstCheck.h" #include "MisplacedWideningCastCheck.h" -#include "MoveConstantArgumentCheck.h" #include "NewDeleteOverloadsCheck.h" -#include "NoexceptMoveConstructorCheck.h" #include "NonCopyableObjects.h" #include "RedundantExpressionCheck.h" #include "SizeofContainerCheck.h" @@ -67,12 +65,8 @@ public: "misc-macro-repeated-side-effects"); CheckFactories.registerCheck<MisplacedWideningCastCheck>( "misc-misplaced-widening-cast"); - CheckFactories.registerCheck<MoveConstantArgumentCheck>( - "misc-move-const-arg"); CheckFactories.registerCheck<NewDeleteOverloadsCheck>( "misc-new-delete-overloads"); - CheckFactories.registerCheck<NoexceptMoveConstructorCheck>( - "misc-noexcept-move-constructor"); CheckFactories.registerCheck<NonCopyableObjectsCheck>( "misc-non-copyable-objects"); CheckFactories.registerCheck<RedundantExpressionCheck>( diff --git a/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp b/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp index 0f4d300aa8e..3aab1693fa8 100644 --- a/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp @@ -187,7 +187,7 @@ void PassByValueCheck::check(const MatchFinder::MatchResult &Result) { return; // If the parameter is trivial to copy, don't move it. Moving a trivivally - // copyable type will cause a problem with misc-move-const-arg + // copyable type will cause a problem with performance-move-const-arg if (ParamDecl->getType().getNonReferenceType().isTriviallyCopyableType( *Result.Context)) return; diff --git a/clang-tools-extra/clang-tidy/performance/CMakeLists.txt b/clang-tools-extra/clang-tidy/performance/CMakeLists.txt index 67594332d82..ac417bcc875 100644 --- a/clang-tools-extra/clang-tidy/performance/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/performance/CMakeLists.txt @@ -7,7 +7,9 @@ add_clang_library(clangTidyPerformanceModule InefficientAlgorithmCheck.cpp InefficientStringConcatenationCheck.cpp InefficientVectorOperationCheck.cpp + MoveConstArgCheck.cpp MoveConstructorInitCheck.cpp + NoexceptMoveConstructorCheck.cpp PerformanceTidyModule.cpp TypePromotionInMathFnCheck.cpp UnnecessaryCopyInitialization.cpp diff --git a/clang-tools-extra/clang-tidy/misc/MoveConstantArgumentCheck.cpp b/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp index 196d982eff1..8d49480298d 100644 --- a/clang-tools-extra/clang-tidy/misc/MoveConstantArgumentCheck.cpp +++ b/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp @@ -1,4 +1,4 @@ -//===--- MoveConstantArgumentCheck.cpp - clang-tidy -----------------------===// +//===--- MoveConstArgCheck.cpp - clang-tidy -----------------------===// // // The LLVM Compiler Infrastructure // @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// -#include "MoveConstantArgumentCheck.h" +#include "MoveConstArgCheck.h" #include "clang/Lex/Lexer.h" @@ -15,7 +15,7 @@ using namespace clang::ast_matchers; namespace clang { namespace tidy { -namespace misc { +namespace performance { static void ReplaceCallWithArg(const CallExpr *Call, DiagnosticBuilder &Diag, const SourceManager &SM, @@ -36,12 +36,11 @@ static void ReplaceCallWithArg(const CallExpr *Call, DiagnosticBuilder &Diag, } } -void MoveConstantArgumentCheck::storeOptions( - ClangTidyOptions::OptionMap &Opts) { +void MoveConstArgCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "CheckTriviallyCopyableMove", CheckTriviallyCopyableMove); } -void MoveConstantArgumentCheck::registerMatchers(MatchFinder *Finder) { +void MoveConstArgCheck::registerMatchers(MatchFinder *Finder) { if (!getLangOpts().CPlusPlus) return; @@ -60,7 +59,7 @@ void MoveConstantArgumentCheck::registerMatchers(MatchFinder *Finder) { this); } -void MoveConstantArgumentCheck::check(const MatchFinder::MatchResult &Result) { +void MoveConstArgCheck::check(const MatchFinder::MatchResult &Result) { const auto *CallMove = Result.Nodes.getNodeAs<CallExpr>("call-move"); const auto *ReceivingExpr = Result.Nodes.getNodeAs<Expr>("receiving-expr"); const Expr *Arg = CallMove->getArg(0); @@ -117,6 +116,6 @@ void MoveConstantArgumentCheck::check(const MatchFinder::MatchResult &Result) { } } -} // namespace misc +} // namespace performance } // namespace tidy } // namespace clang diff --git a/clang-tools-extra/clang-tidy/misc/MoveConstantArgumentCheck.h b/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.h index 85764720652..13ed9aeee0f 100644 --- a/clang-tools-extra/clang-tidy/misc/MoveConstantArgumentCheck.h +++ b/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.h @@ -1,4 +1,4 @@ -//===--- MoveConstantArgumentCheck.h - clang-tidy -------------------------===// +//===--- MoveConstArgCheck.h - clang-tidy -------------------------===// // // The LLVM Compiler Infrastructure // @@ -14,7 +14,7 @@ namespace clang { namespace tidy { -namespace misc { +namespace performance { /// Find casts of calculation results to bigger type. Typically from int to /// @@ -22,9 +22,9 @@ namespace misc { /// /// - `CheckTriviallyCopyableMove`: Whether to check for trivially-copyable // types as their objects are not moved but copied. Enabled by default. -class MoveConstantArgumentCheck : public ClangTidyCheck { +class MoveConstArgCheck : public ClangTidyCheck { public: - MoveConstantArgumentCheck(StringRef Name, ClangTidyContext *Context) + MoveConstArgCheck(StringRef Name, ClangTidyContext *Context) : ClangTidyCheck(Name, Context), CheckTriviallyCopyableMove( Options.get("CheckTriviallyCopyableMove", true)) {} @@ -36,7 +36,7 @@ private: const bool CheckTriviallyCopyableMove; }; -} // namespace misc +} // namespace performance } // namespace tidy } // namespace clang diff --git a/clang-tools-extra/clang-tidy/misc/NoexceptMoveConstructorCheck.cpp b/clang-tools-extra/clang-tidy/performance/NoexceptMoveConstructorCheck.cpp index 12a360f4ba7..86ef70ce094 100644 --- a/clang-tools-extra/clang-tidy/misc/NoexceptMoveConstructorCheck.cpp +++ b/clang-tools-extra/clang-tidy/performance/NoexceptMoveConstructorCheck.cpp @@ -15,7 +15,7 @@ using namespace clang::ast_matchers; namespace clang { namespace tidy { -namespace misc { +namespace performance { void NoexceptMoveConstructorCheck::registerMatchers(MatchFinder *Finder) { // Only register the matchers for C++11; the functionality currently does not @@ -48,30 +48,30 @@ void NoexceptMoveConstructorCheck::check( return; switch (ProtoType->getNoexceptSpec(*Result.Context)) { - case FunctionProtoType::NR_NoNoexcept: - diag(Decl->getLocation(), "move %0s should be marked noexcept") + case FunctionProtoType::NR_NoNoexcept: + diag(Decl->getLocation(), "move %0s should be marked noexcept") + << MethodType; + // FIXME: Add a fixit. + break; + case FunctionProtoType::NR_Throw: + // Don't complain about nothrow(false), but complain on nothrow(expr) + // where expr evaluates to false. + if (const Expr *E = ProtoType->getNoexceptExpr()) { + if (isa<CXXBoolLiteralExpr>(E)) + break; + diag(E->getExprLoc(), + "noexcept specifier on the move %0 evaluates to 'false'") << MethodType; - // FIXME: Add a fixit. - break; - case FunctionProtoType::NR_Throw: - // Don't complain about nothrow(false), but complain on nothrow(expr) - // where expr evaluates to false. - if (const Expr *E = ProtoType->getNoexceptExpr()) { - if (isa<CXXBoolLiteralExpr>(E)) - break; - diag(E->getExprLoc(), - "noexcept specifier on the move %0 evaluates to 'false'") - << MethodType; - } - break; - case FunctionProtoType::NR_Nothrow: - case FunctionProtoType::NR_Dependent: - case FunctionProtoType::NR_BadNoexcept: - break; + } + break; + case FunctionProtoType::NR_Nothrow: + case FunctionProtoType::NR_Dependent: + case FunctionProtoType::NR_BadNoexcept: + break; } } } -} // namespace misc +} // namespace performance } // namespace tidy } // namespace clang diff --git a/clang-tools-extra/clang-tidy/misc/NoexceptMoveConstructorCheck.h b/clang-tools-extra/clang-tidy/performance/NoexceptMoveConstructorCheck.h index e6a0ef9284f..9687ab1f078 100644 --- a/clang-tools-extra/clang-tidy/misc/NoexceptMoveConstructorCheck.h +++ b/clang-tools-extra/clang-tidy/performance/NoexceptMoveConstructorCheck.h @@ -7,14 +7,14 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_NOEXCEPTMOVECONSTRUCTORCHECK_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_NOEXCEPTMOVECONSTRUCTORCHECK_H +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTMOVECONSTRUCTORCHECK_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTMOVECONSTRUCTORCHECK_H #include "../ClangTidy.h" namespace clang { namespace tidy { -namespace misc { +namespace performance { /// The check flags user-defined move constructors and assignment operators not /// marked with `noexcept` or marked with `noexcept(expr)` where `expr` @@ -31,8 +31,8 @@ public: void check(const ast_matchers::MatchFinder::MatchResult &Result) override; }; -} // namespace misc +} // namespace performance } // namespace tidy } // namespace clang -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_NOEXCEPTMOVECONSTRUCTORCHECK_H +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTMOVECONSTRUCTORCHECK_H diff --git a/clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp b/clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp index 51a8728bf73..646c6595600 100644 --- a/clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp @@ -16,7 +16,9 @@ #include "InefficientAlgorithmCheck.h" #include "InefficientStringConcatenationCheck.h" #include "InefficientVectorOperationCheck.h" +#include "MoveConstArgCheck.h" #include "MoveConstructorInitCheck.h" +#include "NoexceptMoveConstructorCheck.h" #include "TypePromotionInMathFnCheck.h" #include "UnnecessaryCopyInitialization.h" #include "UnnecessaryValueParamCheck.h" @@ -40,8 +42,12 @@ public: "performance-inefficient-string-concatenation"); CheckFactories.registerCheck<InefficientVectorOperationCheck>( "performance-inefficient-vector-operation"); + CheckFactories.registerCheck<MoveConstArgCheck>( + "performance-move-const-arg"); CheckFactories.registerCheck<MoveConstructorInitCheck>( "performance-move-constructor-init"); + CheckFactories.registerCheck<NoexceptMoveConstructorCheck>( + "performance-noexcept-move-constructor"); CheckFactories.registerCheck<TypePromotionInMathFnCheck>( "performance-type-promotion-in-math-fn"); CheckFactories.registerCheck<UnnecessaryCopyInitialization>( |