Author: alexfh Date: Mon Nov 27 05:06:28 2017 New Revision: 319023 URL: http://llvm.org/viewvc/llvm-project?rev=319023&view=rev Log: [clang-tidy] Move checks from misc- to performance-
Summary: rename_check.py misc-move-constructor-init performance-move-constructor-init rename_check.py misc-inefficient-algorithm performance-inefficient-algorithm Reviewers: hokein, aaron.ballman Reviewed By: hokein, aaron.ballman Subscribers: aaron.ballman, mgorny, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D40487 Added: clang-tools-extra/trunk/clang-tidy/performance/InefficientAlgorithmCheck.cpp - copied, changed from r319021, clang-tools-extra/trunk/clang-tidy/misc/InefficientAlgorithmCheck.cpp clang-tools-extra/trunk/clang-tidy/performance/InefficientAlgorithmCheck.h - copied, changed from r319021, clang-tools-extra/trunk/clang-tidy/misc/InefficientAlgorithmCheck.h clang-tools-extra/trunk/clang-tidy/performance/MoveConstructorInitCheck.cpp - copied, changed from r319021, clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.cpp clang-tools-extra/trunk/clang-tidy/performance/MoveConstructorInitCheck.h - copied, changed from r319021, clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.h clang-tools-extra/trunk/docs/clang-tidy/checks/performance-inefficient-algorithm.rst - copied, changed from r319021, clang-tools-extra/trunk/docs/clang-tidy/checks/misc-inefficient-algorithm.rst clang-tools-extra/trunk/docs/clang-tidy/checks/performance-move-constructor-init.rst - copied, changed from r319021, clang-tools-extra/trunk/docs/clang-tidy/checks/misc-move-constructor-init.rst clang-tools-extra/trunk/test/clang-tidy/performance-inefficient-algorithm.cpp - copied, changed from r319021, clang-tools-extra/trunk/test/clang-tidy/misc-inefficient-algorithm.cpp clang-tools-extra/trunk/test/clang-tidy/performance-move-constructor-init.cpp - copied, changed from r319021, clang-tools-extra/trunk/test/clang-tidy/misc-move-constructor-init.cpp Removed: clang-tools-extra/trunk/clang-tidy/misc/InefficientAlgorithmCheck.cpp clang-tools-extra/trunk/clang-tidy/misc/InefficientAlgorithmCheck.h clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.cpp clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.h clang-tools-extra/trunk/docs/clang-tidy/checks/misc-inefficient-algorithm.rst clang-tools-extra/trunk/docs/clang-tidy/checks/misc-move-constructor-init.rst clang-tools-extra/trunk/test/clang-tidy/misc-inefficient-algorithm.cpp clang-tools-extra/trunk/test/clang-tidy/misc-move-constructor-init.cpp Modified: clang-tools-extra/trunk/clang-tidy/cert/CERTTidyModule.cpp clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp clang-tools-extra/trunk/clang-tidy/performance/CMakeLists.txt clang-tools-extra/trunk/clang-tidy/performance/PerformanceTidyModule.cpp clang-tools-extra/trunk/docs/ReleaseNotes.rst clang-tools-extra/trunk/docs/clang-tidy/checks/cert-oop11-cpp.rst clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst clang-tools-extra/trunk/test/clang-tidy/cert-oop11-cpp.cpp Modified: clang-tools-extra/trunk/clang-tidy/cert/CERTTidyModule.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cert/CERTTidyModule.cpp?rev=319023&r1=319022&r2=319023&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/cert/CERTTidyModule.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/cert/CERTTidyModule.cpp Mon Nov 27 05:06:28 2017 @@ -11,11 +11,11 @@ #include "../ClangTidyModule.h" #include "../ClangTidyModuleRegistry.h" #include "../google/UnnamedNamespaceInHeaderCheck.h" -#include "../misc/MoveConstructorInitCheck.h" #include "../misc/NewDeleteOverloadsCheck.h" #include "../misc/NonCopyableObjects.h" #include "../misc/StaticAssertCheck.h" #include "../misc/ThrowByValueCatchByReferenceCheck.h" +#include "../performance/MoveConstructorInitCheck.h" #include "CommandProcessorCheck.h" #include "DontModifyStdNamespaceCheck.h" #include "FloatLoopCounter.h" @@ -46,7 +46,7 @@ public: CheckFactories.registerCheck<google::build::UnnamedNamespaceInHeaderCheck>( "cert-dcl59-cpp"); // OOP - CheckFactories.registerCheck<misc::MoveConstructorInitCheck>( + CheckFactories.registerCheck<performance::MoveConstructorInitCheck>( "cert-oop11-cpp"); // ERR CheckFactories.registerCheck<misc::ThrowByValueCatchByReferenceCheck>( Modified: clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt?rev=319023&r1=319022&r2=319023&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt (original) +++ clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt Mon Nov 27 05:06:28 2017 @@ -7,13 +7,11 @@ add_clang_library(clangTidyMiscModule UnconventionalAssignOperatorCheck.cpp DefinitionsInHeadersCheck.cpp IncorrectRoundings.cpp - InefficientAlgorithmCheck.cpp MacroParenthesesCheck.cpp MacroRepeatedSideEffectsCheck.cpp MiscTidyModule.cpp MisplacedWideningCastCheck.cpp MoveConstantArgumentCheck.cpp - MoveConstructorInitCheck.cpp NewDeleteOverloadsCheck.cpp NoexceptMoveConstructorCheck.cpp NonCopyableObjects.cpp Removed: clang-tools-extra/trunk/clang-tidy/misc/InefficientAlgorithmCheck.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/InefficientAlgorithmCheck.cpp?rev=319022&view=auto ============================================================================== --- clang-tools-extra/trunk/clang-tidy/misc/InefficientAlgorithmCheck.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/misc/InefficientAlgorithmCheck.cpp (removed) @@ -1,163 +0,0 @@ -//===--- InefficientAlgorithmCheck.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 "InefficientAlgorithmCheck.h" -#include "clang/AST/ASTContext.h" -#include "clang/ASTMatchers/ASTMatchFinder.h" -#include "clang/Lex/Lexer.h" - -using namespace clang::ast_matchers; - -namespace clang { -namespace tidy { -namespace misc { - -static bool areTypesCompatible(QualType Left, QualType Right) { - if (const auto *LeftRefType = Left->getAs<ReferenceType>()) - Left = LeftRefType->getPointeeType(); - if (const auto *RightRefType = Right->getAs<ReferenceType>()) - Right = RightRefType->getPointeeType(); - return Left->getCanonicalTypeUnqualified() == - Right->getCanonicalTypeUnqualified(); -} - -void InefficientAlgorithmCheck::registerMatchers(MatchFinder *Finder) { - // Only register the matchers for C++; the functionality currently does not - // provide any benefit to other languages, despite being benign. - if (!getLangOpts().CPlusPlus) - return; - - const auto Algorithms = - hasAnyName("::std::find", "::std::count", "::std::equal_range", - "::std::lower_bound", "::std::upper_bound"); - const auto ContainerMatcher = classTemplateSpecializationDecl(hasAnyName( - "::std::set", "::std::map", "::std::multiset", "::std::multimap", - "::std::unordered_set", "::std::unordered_map", - "::std::unordered_multiset", "::std::unordered_multimap")); - - const auto Matcher = - callExpr( - callee(functionDecl(Algorithms)), - hasArgument( - 0, cxxConstructExpr(has(ignoringParenImpCasts(cxxMemberCallExpr( - callee(cxxMethodDecl(hasName("begin"))), - on(declRefExpr( - hasDeclaration(decl().bind("IneffContObj")), - anyOf(hasType(ContainerMatcher.bind("IneffCont")), - hasType(pointsTo( - ContainerMatcher.bind("IneffContPtr"))))) - .bind("IneffContExpr"))))))), - hasArgument( - 1, cxxConstructExpr(has(ignoringParenImpCasts(cxxMemberCallExpr( - callee(cxxMethodDecl(hasName("end"))), - on(declRefExpr( - hasDeclaration(equalsBoundNode("IneffContObj"))))))))), - hasArgument(2, expr().bind("AlgParam")), - unless(isInTemplateInstantiation())) - .bind("IneffAlg"); - - Finder->addMatcher(Matcher, this); -} - -void InefficientAlgorithmCheck::check(const MatchFinder::MatchResult &Result) { - const auto *AlgCall = Result.Nodes.getNodeAs<CallExpr>("IneffAlg"); - const auto *IneffCont = - Result.Nodes.getNodeAs<ClassTemplateSpecializationDecl>("IneffCont"); - bool PtrToContainer = false; - if (!IneffCont) { - IneffCont = - Result.Nodes.getNodeAs<ClassTemplateSpecializationDecl>("IneffContPtr"); - PtrToContainer = true; - } - const llvm::StringRef IneffContName = IneffCont->getName(); - const bool Unordered = - IneffContName.find("unordered") != llvm::StringRef::npos; - const bool Maplike = IneffContName.find("map") != llvm::StringRef::npos; - - // Store if the key type of the container is compatible with the value - // that is searched for. - QualType ValueType = AlgCall->getArg(2)->getType(); - QualType KeyType = - IneffCont->getTemplateArgs()[0].getAsType().getCanonicalType(); - const bool CompatibleTypes = areTypesCompatible(KeyType, ValueType); - - // Check if the comparison type for the algorithm and the container matches. - if (AlgCall->getNumArgs() == 4 && !Unordered) { - const Expr *Arg = AlgCall->getArg(3); - const QualType AlgCmp = - Arg->getType().getUnqualifiedType().getCanonicalType(); - const unsigned CmpPosition = - (IneffContName.find("map") == llvm::StringRef::npos) ? 1 : 2; - const QualType ContainerCmp = IneffCont->getTemplateArgs()[CmpPosition] - .getAsType() - .getUnqualifiedType() - .getCanonicalType(); - if (AlgCmp != ContainerCmp) { - diag(Arg->getLocStart(), - "different comparers used in the algorithm and the container"); - return; - } - } - - const auto *AlgDecl = AlgCall->getDirectCallee(); - if (!AlgDecl) - return; - - if (Unordered && AlgDecl->getName().find("bound") != llvm::StringRef::npos) - return; - - const auto *AlgParam = Result.Nodes.getNodeAs<Expr>("AlgParam"); - const auto *IneffContExpr = Result.Nodes.getNodeAs<Expr>("IneffContExpr"); - FixItHint Hint; - - SourceManager &SM = *Result.SourceManager; - LangOptions LangOpts = getLangOpts(); - - CharSourceRange CallRange = - CharSourceRange::getTokenRange(AlgCall->getSourceRange()); - - // FIXME: Create a common utility to extract a file range that the given token - // sequence is exactly spelled at (without macro argument expansions etc.). - // We can't use Lexer::makeFileCharRange here, because for - // - // #define F(x) x - // x(a b c); - // - // it will return "x(a b c)", when given the range "a"-"c". It makes sense for - // removals, but not for replacements. - // - // This code is over-simplified, but works for many real cases. - if (SM.isMacroArgExpansion(CallRange.getBegin()) && - SM.isMacroArgExpansion(CallRange.getEnd())) { - CallRange.setBegin(SM.getSpellingLoc(CallRange.getBegin())); - CallRange.setEnd(SM.getSpellingLoc(CallRange.getEnd())); - } - - if (!CallRange.getBegin().isMacroID() && !Maplike && CompatibleTypes) { - StringRef ContainerText = Lexer::getSourceText( - CharSourceRange::getTokenRange(IneffContExpr->getSourceRange()), SM, - LangOpts); - StringRef ParamText = Lexer::getSourceText( - CharSourceRange::getTokenRange(AlgParam->getSourceRange()), SM, - LangOpts); - std::string ReplacementText = - (llvm::Twine(ContainerText) + (PtrToContainer ? "->" : ".") + - AlgDecl->getName() + "(" + ParamText + ")") - .str(); - Hint = FixItHint::CreateReplacement(CallRange, ReplacementText); - } - - diag(AlgCall->getLocStart(), - "this STL algorithm call should be replaced with a container method") - << Hint; -} - -} // namespace misc -} // namespace tidy -} // namespace clang Removed: clang-tools-extra/trunk/clang-tidy/misc/InefficientAlgorithmCheck.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/InefficientAlgorithmCheck.h?rev=319022&view=auto ============================================================================== --- clang-tools-extra/trunk/clang-tidy/misc/InefficientAlgorithmCheck.h (original) +++ clang-tools-extra/trunk/clang-tidy/misc/InefficientAlgorithmCheck.h (removed) @@ -1,36 +0,0 @@ -//===--- InefficientAlgorithmCheck.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_INEFFICIENTALGORITHMCHECK_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_INEFFICIENTALGORITHMCHECK_H - -#include "../ClangTidy.h" - -namespace clang { -namespace tidy { -namespace misc { - -/// Warns on inefficient use of STL algorithms on associative containers. -/// -/// Associative containers implements some of the algorithms as methods which -/// should be preferred to the algorithms in the algorithm header. The methods -/// can take advanatage of the order of the elements. -class InefficientAlgorithmCheck : public ClangTidyCheck { -public: - InefficientAlgorithmCheck(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_INEFFICIENTALGORITHMCHECK_H Modified: clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp?rev=319023&r1=319022&r2=319023&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp Mon Nov 27 05:06:28 2017 @@ -13,14 +13,12 @@ #include "DefinitionsInHeadersCheck.h" #include "ForwardingReferenceOverloadCheck.h" #include "IncorrectRoundings.h" -#include "InefficientAlgorithmCheck.h" #include "LambdaFunctionNameCheck.h" #include "MacroParenthesesCheck.h" #include "MacroRepeatedSideEffectsCheck.h" #include "MisplacedConstCheck.h" #include "MisplacedWideningCastCheck.h" #include "MoveConstantArgumentCheck.h" -#include "MoveConstructorInitCheck.h" #include "NewDeleteOverloadsCheck.h" #include "NoexceptMoveConstructorCheck.h" #include "NonCopyableObjects.h" @@ -63,8 +61,6 @@ public: "misc-definitions-in-headers"); CheckFactories.registerCheck<IncorrectRoundings>( "misc-incorrect-roundings"); - CheckFactories.registerCheck<InefficientAlgorithmCheck>( - "misc-inefficient-algorithm"); CheckFactories.registerCheck<MacroParenthesesCheck>( "misc-macro-parentheses"); CheckFactories.registerCheck<MacroRepeatedSideEffectsCheck>( @@ -73,8 +69,6 @@ public: "misc-misplaced-widening-cast"); CheckFactories.registerCheck<MoveConstantArgumentCheck>( "misc-move-const-arg"); - CheckFactories.registerCheck<MoveConstructorInitCheck>( - "misc-move-constructor-init"); CheckFactories.registerCheck<NewDeleteOverloadsCheck>( "misc-new-delete-overloads"); CheckFactories.registerCheck<NoexceptMoveConstructorCheck>( Removed: clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.cpp?rev=319022&view=auto ============================================================================== --- clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.cpp (removed) @@ -1,110 +0,0 @@ -//===--- MoveConstructorInitCheck.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 "MoveConstructorInitCheck.h" -#include "../utils/Matchers.h" -#include "clang/AST/ASTContext.h" -#include "clang/ASTMatchers/ASTMatchFinder.h" -#include "clang/Frontend/CompilerInstance.h" -#include "clang/Lex/Lexer.h" -#include "clang/Lex/Preprocessor.h" - -using namespace clang::ast_matchers; - -namespace clang { -namespace tidy { -namespace misc { - -MoveConstructorInitCheck::MoveConstructorInitCheck(StringRef Name, - ClangTidyContext *Context) - : ClangTidyCheck(Name, Context), - IncludeStyle(utils::IncludeSorter::parseIncludeStyle( - Options.getLocalOrGlobal("IncludeStyle", "llvm"))) {} - -void MoveConstructorInitCheck::registerMatchers(MatchFinder *Finder) { - // Only register the matchers for C++11; the functionality currently does not - // provide any benefit to other languages, despite being benign. - if (!getLangOpts().CPlusPlus11) - return; - - Finder->addMatcher( - cxxConstructorDecl( - unless(isImplicit()), - allOf(isMoveConstructor(), - hasAnyConstructorInitializer( - cxxCtorInitializer( - withInitializer(cxxConstructExpr(hasDeclaration( - cxxConstructorDecl(isCopyConstructor()) - .bind("ctor"))))) - .bind("move-init")))), - this); -} - -void MoveConstructorInitCheck::check(const MatchFinder::MatchResult &Result) { - const auto *CopyCtor = Result.Nodes.getNodeAs<CXXConstructorDecl>("ctor"); - const auto *Initializer = - Result.Nodes.getNodeAs<CXXCtorInitializer>("move-init"); - - // Do not diagnose if the expression used to perform the initialization is a - // trivially-copyable type. - QualType QT = Initializer->getInit()->getType(); - if (QT.isTriviallyCopyableType(*Result.Context)) - return; - - if (QT.isConstQualified()) - return; - - const auto *RD = QT->getAsCXXRecordDecl(); - if (RD && RD->isTriviallyCopyable()) - return; - - // Diagnose when the class type has a move constructor available, but the - // ctor-initializer uses the copy constructor instead. - const CXXConstructorDecl *Candidate = nullptr; - for (const auto *Ctor : CopyCtor->getParent()->ctors()) { - if (Ctor->isMoveConstructor() && Ctor->getAccess() <= AS_protected && - !Ctor->isDeleted()) { - // The type has a move constructor that is at least accessible to the - // initializer. - // - // FIXME: Determine whether the move constructor is a viable candidate - // for the ctor-initializer, perhaps provide a fixit that suggests - // using std::move(). - Candidate = Ctor; - break; - } - } - - if (Candidate) { - // There's a move constructor candidate that the caller probably intended - // to call instead. - diag(Initializer->getSourceLocation(), - "move constructor initializes %0 by calling a copy constructor") - << (Initializer->isBaseInitializer() ? "base class" : "class member"); - diag(CopyCtor->getLocation(), "copy constructor being called", - DiagnosticIDs::Note); - diag(Candidate->getLocation(), "candidate move constructor here", - DiagnosticIDs::Note); - } -} - -void MoveConstructorInitCheck::registerPPCallbacks(CompilerInstance &Compiler) { - Inserter.reset(new utils::IncludeInserter( - Compiler.getSourceManager(), Compiler.getLangOpts(), IncludeStyle)); - Compiler.getPreprocessor().addPPCallbacks(Inserter->CreatePPCallbacks()); -} - -void MoveConstructorInitCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { - Options.store(Opts, "IncludeStyle", - utils::IncludeSorter::toString(IncludeStyle)); -} - -} // namespace misc -} // namespace tidy -} // namespace clang Removed: clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.h?rev=319022&view=auto ============================================================================== --- clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.h (original) +++ clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.h (removed) @@ -1,44 +0,0 @@ -//===--- MoveConstructorInitCheck.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_MOVECONSTRUCTORINITCHECK_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MOVECONSTRUCTORINITCHECK_H - -#include "../ClangTidy.h" -#include "../utils/IncludeInserter.h" - -#include <memory> - -namespace clang { -namespace tidy { -namespace misc { - -/// The check flags user-defined move constructors that have a ctor-initializer -/// initializing a member or base class through a copy constructor instead of a -/// move constructor. -/// For the user-facing documentation see: -/// http://clang.llvm.org/extra/clang-tidy/checks/misc-move-constructor-init.html -class MoveConstructorInitCheck : public ClangTidyCheck { -public: - MoveConstructorInitCheck(StringRef Name, ClangTidyContext *Context); - void registerMatchers(ast_matchers::MatchFinder *Finder) override; - void check(const ast_matchers::MatchFinder::MatchResult &Result) override; - void registerPPCallbacks(clang::CompilerInstance &Compiler) override; - void storeOptions(ClangTidyOptions::OptionMap &Opts) override; - -private: - std::unique_ptr<utils::IncludeInserter> Inserter; - const utils::IncludeSorter::IncludeStyle IncludeStyle; -}; - -} // namespace misc -} // namespace tidy -} // namespace clang - -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MOVECONSTRUCTORINITCHECK_H Modified: clang-tools-extra/trunk/clang-tidy/performance/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/performance/CMakeLists.txt?rev=319023&r1=319022&r2=319023&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/performance/CMakeLists.txt (original) +++ clang-tools-extra/trunk/clang-tidy/performance/CMakeLists.txt Mon Nov 27 05:06:28 2017 @@ -4,8 +4,10 @@ add_clang_library(clangTidyPerformanceMo FasterStringFindCheck.cpp ForRangeCopyCheck.cpp ImplicitConversionInLoopCheck.cpp + InefficientAlgorithmCheck.cpp InefficientStringConcatenationCheck.cpp InefficientVectorOperationCheck.cpp + MoveConstructorInitCheck.cpp PerformanceTidyModule.cpp TypePromotionInMathFnCheck.cpp UnnecessaryCopyInitialization.cpp Copied: clang-tools-extra/trunk/clang-tidy/performance/InefficientAlgorithmCheck.cpp (from r319021, clang-tools-extra/trunk/clang-tidy/misc/InefficientAlgorithmCheck.cpp) URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/performance/InefficientAlgorithmCheck.cpp?p2=clang-tools-extra/trunk/clang-tidy/performance/InefficientAlgorithmCheck.cpp&p1=clang-tools-extra/trunk/clang-tidy/misc/InefficientAlgorithmCheck.cpp&r1=319021&r2=319023&rev=319023&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/misc/InefficientAlgorithmCheck.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/performance/InefficientAlgorithmCheck.cpp Mon Nov 27 05:06:28 2017 @@ -16,7 +16,7 @@ using namespace clang::ast_matchers; namespace clang { namespace tidy { -namespace misc { +namespace performance { static bool areTypesCompatible(QualType Left, QualType Right) { if (const auto *LeftRefType = Left->getAs<ReferenceType>()) @@ -158,6 +158,6 @@ void InefficientAlgorithmCheck::check(co << Hint; } -} // namespace misc +} // namespace performance } // namespace tidy } // namespace clang Copied: clang-tools-extra/trunk/clang-tidy/performance/InefficientAlgorithmCheck.h (from r319021, clang-tools-extra/trunk/clang-tidy/misc/InefficientAlgorithmCheck.h) URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/performance/InefficientAlgorithmCheck.h?p2=clang-tools-extra/trunk/clang-tidy/performance/InefficientAlgorithmCheck.h&p1=clang-tools-extra/trunk/clang-tidy/misc/InefficientAlgorithmCheck.h&r1=319021&r2=319023&rev=319023&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/misc/InefficientAlgorithmCheck.h (original) +++ clang-tools-extra/trunk/clang-tidy/performance/InefficientAlgorithmCheck.h Mon Nov 27 05:06:28 2017 @@ -7,14 +7,14 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_INEFFICIENTALGORITHMCHECK_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_INEFFICIENTALGORITHMCHECK_H +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_INEFFICIENTALGORITHMCHECK_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_INEFFICIENTALGORITHMCHECK_H #include "../ClangTidy.h" namespace clang { namespace tidy { -namespace misc { +namespace performance { /// Warns on inefficient use of STL algorithms on associative containers. /// @@ -29,8 +29,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_INEFFICIENTALGORITHMCHECK_H +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_INEFFICIENTALGORITHMCHECK_H Copied: clang-tools-extra/trunk/clang-tidy/performance/MoveConstructorInitCheck.cpp (from r319021, clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.cpp) URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/performance/MoveConstructorInitCheck.cpp?p2=clang-tools-extra/trunk/clang-tidy/performance/MoveConstructorInitCheck.cpp&p1=clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.cpp&r1=319021&r2=319023&rev=319023&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/performance/MoveConstructorInitCheck.cpp Mon Nov 27 05:06:28 2017 @@ -19,7 +19,7 @@ using namespace clang::ast_matchers; namespace clang { namespace tidy { -namespace misc { +namespace performance { MoveConstructorInitCheck::MoveConstructorInitCheck(StringRef Name, ClangTidyContext *Context) @@ -105,6 +105,6 @@ void MoveConstructorInitCheck::storeOpti utils::IncludeSorter::toString(IncludeStyle)); } -} // namespace misc +} // namespace performance } // namespace tidy } // namespace clang Copied: clang-tools-extra/trunk/clang-tidy/performance/MoveConstructorInitCheck.h (from r319021, clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.h) URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/performance/MoveConstructorInitCheck.h?p2=clang-tools-extra/trunk/clang-tidy/performance/MoveConstructorInitCheck.h&p1=clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.h&r1=319021&r2=319023&rev=319023&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.h (original) +++ clang-tools-extra/trunk/clang-tidy/performance/MoveConstructorInitCheck.h Mon Nov 27 05:06:28 2017 @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MOVECONSTRUCTORINITCHECK_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MOVECONSTRUCTORINITCHECK_H +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_MOVECONSTRUCTORINITCHECK_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_MOVECONSTRUCTORINITCHECK_H #include "../ClangTidy.h" #include "../utils/IncludeInserter.h" @@ -17,13 +17,13 @@ namespace clang { namespace tidy { -namespace misc { +namespace performance { /// The check flags user-defined move constructors that have a ctor-initializer /// initializing a member or base class through a copy constructor instead of a /// move constructor. /// For the user-facing documentation see: -/// http://clang.llvm.org/extra/clang-tidy/checks/misc-move-constructor-init.html +/// http://clang.llvm.org/extra/clang-tidy/checks/performance-move-constructor-init.html class MoveConstructorInitCheck : public ClangTidyCheck { public: MoveConstructorInitCheck(StringRef Name, ClangTidyContext *Context); @@ -37,8 +37,8 @@ private: const utils::IncludeSorter::IncludeStyle IncludeStyle; }; -} // namespace misc +} // namespace performance } // namespace tidy } // namespace clang -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MOVECONSTRUCTORINITCHECK_H +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_MOVECONSTRUCTORINITCHECK_H Modified: clang-tools-extra/trunk/clang-tidy/performance/PerformanceTidyModule.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/performance/PerformanceTidyModule.cpp?rev=319023&r1=319022&r2=319023&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/performance/PerformanceTidyModule.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/performance/PerformanceTidyModule.cpp Mon Nov 27 05:06:28 2017 @@ -13,8 +13,10 @@ #include "FasterStringFindCheck.h" #include "ForRangeCopyCheck.h" #include "ImplicitConversionInLoopCheck.h" +#include "InefficientAlgorithmCheck.h" #include "InefficientStringConcatenationCheck.h" #include "InefficientVectorOperationCheck.h" +#include "MoveConstructorInitCheck.h" #include "TypePromotionInMathFnCheck.h" #include "UnnecessaryCopyInitialization.h" #include "UnnecessaryValueParamCheck.h" @@ -32,10 +34,14 @@ public: "performance-for-range-copy"); CheckFactories.registerCheck<ImplicitConversionInLoopCheck>( "performance-implicit-conversion-in-loop"); + CheckFactories.registerCheck<InefficientAlgorithmCheck>( + "performance-inefficient-algorithm"); CheckFactories.registerCheck<InefficientStringConcatenationCheck>( "performance-inefficient-string-concatenation"); CheckFactories.registerCheck<InefficientVectorOperationCheck>( "performance-inefficient-vector-operation"); + CheckFactories.registerCheck<MoveConstructorInitCheck>( + "performance-move-constructor-init"); CheckFactories.registerCheck<TypePromotionInMathFnCheck>( "performance-type-promotion-in-math-fn"); CheckFactories.registerCheck<UnnecessaryCopyInitialization>( Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=319023&r1=319022&r2=319023&view=diff ============================================================================== --- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original) +++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Mon Nov 27 05:06:28 2017 @@ -57,6 +57,12 @@ The improvements are... Improvements to clang-tidy -------------------------- +- The 'misc-move-constructor-init' check was renamed to `performance-move-constructor-init + <http://clang.llvm.org/extra/clang-tidy/checks/performance-move-constructor-init.html>`_ + +- The 'misc-inefficient-algorithm' check was renamed to `performance-inefficient-algorithm + <http://clang.llvm.org/extra/clang-tidy/checks/performance-inefficient-algorithm.html>`_ + - The 'misc-virtual-near-miss' check was renamed to `bugprone-virtual-near-miss <http://clang.llvm.org/extra/clang-tidy/checks/bugprone-virtual-near-miss.html>`_ Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/cert-oop11-cpp.rst URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/cert-oop11-cpp.rst?rev=319023&r1=319022&r2=319023&view=diff ============================================================================== --- clang-tools-extra/trunk/docs/clang-tidy/checks/cert-oop11-cpp.rst (original) +++ clang-tools-extra/trunk/docs/clang-tidy/checks/cert-oop11-cpp.rst Mon Nov 27 05:06:28 2017 @@ -1,10 +1,10 @@ -.. title:: clang-tidy - cert-oop11-cpp -.. meta:: - :http-equiv=refresh: 5;URL=misc-move-constructor-init.html - -cert-oop11-cpp -============== - -The cert-oop11-cpp check is an alias, please see -`misc-move-constructor-init <misc-move-constructor-init.html>`_ for more -information. +.. title:: clang-tidy - cert-oop11-cpp +.. meta:: + :http-equiv=refresh: 5;URL=performance-move-constructor-init.html + +cert-oop11-cpp +============== + +The cert-oop11-cpp check is an alias, please see +`performance-move-constructor-init <performance-move-constructor-init.html>`_ +for more information. Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst?rev=319023&r1=319022&r2=319023&view=diff ============================================================================== --- clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst (original) +++ clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst Mon Nov 27 05:06:28 2017 @@ -51,7 +51,7 @@ Clang-Tidy Checks cert-flp30-c cert-msc30-c (redirects to cert-msc50-cpp) <cert-msc30-c> cert-msc50-cpp - cert-oop11-cpp (redirects to misc-move-constructor-init) <cert-oop11-cpp> + cert-oop11-cpp (redirects to performance-move-constructor-init) <cert-oop11-cpp> cppcoreguidelines-c-copy-assignment-signature (redirects to misc-unconventional-assign-operator) <cppcoreguidelines-c-copy-assignment-signature> cppcoreguidelines-interfaces-global-init cppcoreguidelines-no-malloc @@ -119,14 +119,12 @@ Clang-Tidy Checks misc-definitions-in-headers misc-forwarding-reference-overload misc-incorrect-roundings - misc-inefficient-algorithm misc-lambda-function-name misc-macro-parentheses misc-macro-repeated-side-effects misc-misplaced-const misc-misplaced-widening-cast misc-move-const-arg - misc-move-constructor-init misc-new-delete-overloads misc-noexcept-move-constructor misc-non-copyable-objects @@ -181,8 +179,10 @@ Clang-Tidy Checks performance-faster-string-find performance-for-range-copy performance-implicit-conversion-in-loop + performance-inefficient-algorithm performance-inefficient-string-concatenation performance-inefficient-vector-operation + performance-move-constructor-init performance-type-promotion-in-math-fn performance-unnecessary-copy-initialization performance-unnecessary-value-param Removed: clang-tools-extra/trunk/docs/clang-tidy/checks/misc-inefficient-algorithm.rst URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/misc-inefficient-algorithm.rst?rev=319022&view=auto ============================================================================== --- clang-tools-extra/trunk/docs/clang-tidy/checks/misc-inefficient-algorithm.rst (original) +++ clang-tools-extra/trunk/docs/clang-tidy/checks/misc-inefficient-algorithm.rst (removed) @@ -1,29 +0,0 @@ -.. title:: clang-tidy - misc-inefficient-algorithm - -misc-inefficient-algorithm -========================== - - -Warns on inefficient use of STL algorithms on associative containers. - -Associative containers implements some of the algorithms as methods which -should be preferred to the algorithms in the algorithm header. The methods -can take advanatage of the order of the elements. - -.. code-block:: c++ - - std::set<int> s; - auto it = std::find(s.begin(), s.end(), 43); - - // becomes - - auto it = s.find(43); - -.. code-block:: c++ - - std::set<int> s; - auto c = std::count(s.begin(), s.end(), 43); - - // becomes - - auto c = s.count(43); Removed: clang-tools-extra/trunk/docs/clang-tidy/checks/misc-move-constructor-init.rst URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/misc-move-constructor-init.rst?rev=319022&view=auto ============================================================================== --- clang-tools-extra/trunk/docs/clang-tidy/checks/misc-move-constructor-init.rst (original) +++ clang-tools-extra/trunk/docs/clang-tidy/checks/misc-move-constructor-init.rst (removed) @@ -1,18 +0,0 @@ -.. title:: clang-tidy - misc-move-constructor-init - -misc-move-constructor-init -========================== - -"cert-oop11-cpp" redirects here as an alias for this check. - -The check flags user-defined move constructors that have a ctor-initializer -initializing a member or base class through a copy constructor instead of a -move constructor. - -Options -------- - -.. option:: IncludeStyle - - A string specifying which include-style is used, `llvm` or `google`. Default - is `llvm`. Copied: clang-tools-extra/trunk/docs/clang-tidy/checks/performance-inefficient-algorithm.rst (from r319021, clang-tools-extra/trunk/docs/clang-tidy/checks/misc-inefficient-algorithm.rst) URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/performance-inefficient-algorithm.rst?p2=clang-tools-extra/trunk/docs/clang-tidy/checks/performance-inefficient-algorithm.rst&p1=clang-tools-extra/trunk/docs/clang-tidy/checks/misc-inefficient-algorithm.rst&r1=319021&r2=319023&rev=319023&view=diff ============================================================================== --- clang-tools-extra/trunk/docs/clang-tidy/checks/misc-inefficient-algorithm.rst (original) +++ clang-tools-extra/trunk/docs/clang-tidy/checks/performance-inefficient-algorithm.rst Mon Nov 27 05:06:28 2017 @@ -1,7 +1,7 @@ -.. title:: clang-tidy - misc-inefficient-algorithm +.. title:: clang-tidy - performance-inefficient-algorithm -misc-inefficient-algorithm -========================== +performance-inefficient-algorithm +================================= Warns on inefficient use of STL algorithms on associative containers. Copied: clang-tools-extra/trunk/docs/clang-tidy/checks/performance-move-constructor-init.rst (from r319021, clang-tools-extra/trunk/docs/clang-tidy/checks/misc-move-constructor-init.rst) URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/performance-move-constructor-init.rst?p2=clang-tools-extra/trunk/docs/clang-tidy/checks/performance-move-constructor-init.rst&p1=clang-tools-extra/trunk/docs/clang-tidy/checks/misc-move-constructor-init.rst&r1=319021&r2=319023&rev=319023&view=diff ============================================================================== --- clang-tools-extra/trunk/docs/clang-tidy/checks/misc-move-constructor-init.rst (original) +++ clang-tools-extra/trunk/docs/clang-tidy/checks/performance-move-constructor-init.rst Mon Nov 27 05:06:28 2017 @@ -1,7 +1,7 @@ -.. title:: clang-tidy - misc-move-constructor-init +.. title:: clang-tidy - performance-move-constructor-init -misc-move-constructor-init -========================== +performance-move-constructor-init +================================= "cert-oop11-cpp" redirects here as an alias for this check. Modified: clang-tools-extra/trunk/test/clang-tidy/cert-oop11-cpp.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cert-oop11-cpp.cpp?rev=319023&r1=319022&r2=319023&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clang-tidy/cert-oop11-cpp.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/cert-oop11-cpp.cpp Mon Nov 27 05:06:28 2017 @@ -16,6 +16,6 @@ struct D { // This should not produce a diagnostic because it is not covered under // the CERT guideline for OOP11-CPP. However, this will produce a diagnostic - // under misc-move-constructor-init. + // under performance-move-constructor-init. D(B b) : b(b) {} }; Removed: clang-tools-extra/trunk/test/clang-tidy/misc-inefficient-algorithm.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-inefficient-algorithm.cpp?rev=319022&view=auto ============================================================================== --- clang-tools-extra/trunk/test/clang-tidy/misc-inefficient-algorithm.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/misc-inefficient-algorithm.cpp (removed) @@ -1,166 +0,0 @@ -// RUN: %check_clang_tidy %s misc-inefficient-algorithm %t - -namespace std { -template <typename T> struct less { - bool operator()(const T &lhs, const T &rhs) { return lhs < rhs; } -}; - -template <typename T> struct greater { - bool operator()(const T &lhs, const T &rhs) { return lhs > rhs; } -}; - -struct iterator_type {}; - -template <typename K, typename Cmp = less<K>> struct set { - typedef iterator_type iterator; - iterator find(const K &k); - unsigned count(const K &k); - - iterator begin(); - iterator end(); - iterator begin() const; - iterator end() const; -}; - -struct other_iterator_type {}; - -template <typename K, typename V, typename Cmp = less<K>> struct map { - typedef other_iterator_type iterator; - iterator find(const K &k); - unsigned count(const K &k); - - iterator begin(); - iterator end(); - iterator begin() const; - iterator end() const; -}; - -template <typename K, typename V> struct multimap : map<K, V> {}; -template <typename K> struct unordered_set : set<K> {}; -template <typename K, typename V> struct unordered_map : map<K, V> {}; -template <typename K> struct unordered_multiset : set<K> {}; -template <typename K, typename V> struct unordered_multimap : map<K, V> {}; - -template <typename K, typename Cmp = less<K>> struct multiset : set<K, Cmp> {}; - -template <typename FwIt, typename K> -FwIt find(FwIt, FwIt end, const K &) { return end; } - -template <typename FwIt, typename K, typename Cmp> -FwIt find(FwIt, FwIt end, const K &, Cmp) { return end; } - -template <typename FwIt, typename Pred> -FwIt find_if(FwIt, FwIt end, Pred) { return end; } - -template <typename FwIt, typename K> -unsigned count(FwIt, FwIt, const K &) { return 0; } - -template <typename FwIt, typename K> -FwIt lower_bound(FwIt, FwIt end, const K &) { return end; } - -template <typename FwIt, typename K, typename Ord> -FwIt lower_bound(FwIt, FwIt end, const K &, Ord) { return end; } -} - -#define FIND_IN_SET(x) find(x.begin(), x.end(), 10) -// CHECK-FIXES: #define FIND_IN_SET(x) find(x.begin(), x.end(), 10) - -template <typename T> void f(const T &t) { - std::set<int> s; - find(s.begin(), s.end(), 46); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be - // CHECK-FIXES: {{^ }}s.find(46);{{$}} - - find(t.begin(), t.end(), 46); - // CHECK-FIXES: {{^ }}find(t.begin(), t.end(), 46);{{$}} -} - -int main() { - std::set<int> s; - auto it = std::find(s.begin(), s.end(), 43); - // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: this STL algorithm call should be replaced with a container method [misc-inefficient-algorithm] - // CHECK-FIXES: {{^ }}auto it = s.find(43);{{$}} - auto c = count(s.begin(), s.end(), 43); - // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: this STL algorithm call should be - // CHECK-FIXES: {{^ }}auto c = s.count(43);{{$}} - -#define SECOND(x, y, z) y - SECOND(q,std::count(s.begin(), s.end(), 22),w); - // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: this STL algorithm call should be - // CHECK-FIXES: {{^ }}SECOND(q,s.count(22),w);{{$}} - - it = find_if(s.begin(), s.end(), [](int) { return false; }); - - std::multiset<int> ms; - find(ms.begin(), ms.end(), 46); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be - // CHECK-FIXES: {{^ }}ms.find(46);{{$}} - - const std::multiset<int> &msref = ms; - find(msref.begin(), msref.end(), 46); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be - // CHECK-FIXES: {{^ }}msref.find(46);{{$}} - - std::multiset<int> *msptr = &ms; - find(msptr->begin(), msptr->end(), 46); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be - // CHECK-FIXES: {{^ }}msptr->find(46);{{$}} - - it = std::find(s.begin(), s.end(), 43, std::greater<int>()); - // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: different comparers used in the algorithm and the container [misc-inefficient-algorithm] - - FIND_IN_SET(s); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be - // CHECK-FIXES: {{^ }}FIND_IN_SET(s);{{$}} - - f(s); - - std::unordered_set<int> us; - lower_bound(us.begin(), us.end(), 10); - // CHECK-FIXES: {{^ }}lower_bound(us.begin(), us.end(), 10);{{$}} - find(us.begin(), us.end(), 10); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be - // CHECK-FIXES: {{^ }}us.find(10);{{$}} - - std::unordered_multiset<int> ums; - find(ums.begin(), ums.end(), 10); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be - // CHECK-FIXES: {{^ }}ums.find(10);{{$}} - - std::map<int, int> intmap; - find(intmap.begin(), intmap.end(), 46); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be - // CHECK-FIXES: {{^ }}find(intmap.begin(), intmap.end(), 46);{{$}} - - std::multimap<int, int> intmmap; - find(intmmap.begin(), intmmap.end(), 46); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be - // CHECK-FIXES: {{^ }}find(intmmap.begin(), intmmap.end(), 46);{{$}} - - std::unordered_map<int, int> umap; - find(umap.begin(), umap.end(), 46); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be - // CHECK-FIXES: {{^ }}find(umap.begin(), umap.end(), 46);{{$}} - - std::unordered_multimap<int, int> ummap; - find(ummap.begin(), ummap.end(), 46); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be - // CHECK-FIXES: {{^ }}find(ummap.begin(), ummap.end(), 46);{{$}} -} - -struct Value { - int value; -}; - -struct Ordering { - bool operator()(const Value &lhs, const Value &rhs) const { - return lhs.value < rhs.value; - } - bool operator()(int lhs, const Value &rhs) const { return lhs < rhs.value; } -}; - -void g(std::set<Value, Ordering> container, int value) { - lower_bound(container.begin(), container.end(), value, Ordering()); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be - // CHECK-FIXES: {{^ }}lower_bound(container.begin(), container.end(), value, Ordering());{{$}} -} Removed: clang-tools-extra/trunk/test/clang-tidy/misc-move-constructor-init.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-move-constructor-init.cpp?rev=319022&view=auto ============================================================================== --- clang-tools-extra/trunk/test/clang-tidy/misc-move-constructor-init.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/misc-move-constructor-init.cpp (removed) @@ -1,154 +0,0 @@ -// RUN: %check_clang_tidy %s misc-move-constructor-init,modernize-pass-by-value %t -- \ -// RUN: -config='{CheckOptions: \ -// RUN: [{key: modernize-pass-by-value.ValuesOnly, value: 1}]}' \ -// RUN: -- -std=c++11 -isystem %S/Inputs/Headers - -#include <s.h> - -// CHECK-FIXES: #include <utility> - -template <class T> struct remove_reference {typedef T type;}; -template <class T> struct remove_reference<T&> {typedef T type;}; -template <class T> struct remove_reference<T&&> {typedef T type;}; - -template <typename T> -typename remove_reference<T>::type&& move(T&& arg) { - return static_cast<typename remove_reference<T>::type&&>(arg); -} - -struct C { - C() = default; - C(const C&) = default; -}; - -struct B { - B() {} - B(const B&) {} - B(B &&) {} -}; - -struct D : B { - D() : B() {} - D(const D &RHS) : B(RHS) {} - // CHECK-MESSAGES: :[[@LINE+3]]:16: warning: move constructor initializes base class by calling a copy constructor [misc-move-constructor-init] - // CHECK-MESSAGES: 26:3: note: copy constructor being called - // CHECK-MESSAGES: 27:3: note: candidate move constructor here - D(D &&RHS) : B(RHS) {} -}; - -struct E : B { - E() : B() {} - E(const E &RHS) : B(RHS) {} - E(E &&RHS) : B(move(RHS)) {} // ok -}; - -struct F { - C M; - - F(F &&) : M(C()) {} // ok -}; - -struct G { - G() = default; - G(const G&) = default; - G(G&&) = delete; -}; - -struct H : G { - H() = default; - H(const H&) = default; - H(H &&RHS) : G(RHS) {} // ok -}; - -struct I { - I(const I &) = default; // suppresses move constructor creation -}; - -struct J : I { - J(J &&RHS) : I(RHS) {} // ok -}; - -struct K {}; // Has implicit copy and move constructors, is trivially copyable -struct L : K { - L(L &&RHS) : K(RHS) {} // ok -}; - -struct M { - B Mem; - // CHECK-MESSAGES: :[[@LINE+1]]:16: warning: move constructor initializes class member by calling a copy constructor [misc-move-constructor-init] - M(M &&RHS) : Mem(RHS.Mem) {} -}; - -struct N { - B Mem; - N(N &&RHS) : Mem(move(RHS.Mem)) {} -}; - -struct O { - O(O&& other) : b(other.b) {} // ok - const B b; -}; - -struct P { - P(O&& other) : b(other.b) {} // ok - B b; -}; - -struct Movable { - Movable(Movable &&) = default; - Movable(const Movable &) = default; - Movable &operator=(const Movable &) = default; - ~Movable() {} -}; - -struct TriviallyCopyable { - TriviallyCopyable() = default; - TriviallyCopyable(TriviallyCopyable &&) = default; - TriviallyCopyable(const TriviallyCopyable &) = default; -}; - -struct Positive { - Positive(Movable M) : M_(M) {} - // CHECK-MESSAGES: [[@LINE-1]]:12: warning: pass by value and use std::move [modernize-pass-by-value] - // CHECK-FIXES: Positive(Movable M) : M_(std::move(M)) {} - Movable M_; -}; - -struct NegativeMultipleInitializerReferences { - NegativeMultipleInitializerReferences(Movable M) : M_(M), n_(M) {} - Movable M_; - Movable n_; -}; - -struct NegativeReferencedInConstructorBody { - NegativeReferencedInConstructorBody(Movable M) : M_(M) { M_ = M; } - Movable M_; -}; - -struct NegativeParamTriviallyCopyable { - NegativeParamTriviallyCopyable(TriviallyCopyable T) : T_(T) {} - NegativeParamTriviallyCopyable(int I) : I_(I) {} - - TriviallyCopyable T_; - int I_; -}; - -struct NegativeNotPassedByValue { - // This const ref constructor isn't warned about because the ValuesOnly option is set. - NegativeNotPassedByValue(const Movable &M) : M_(M) {} - NegativeNotPassedByValue(const Movable M) : M_(M) {} - NegativeNotPassedByValue(Movable &M) : M_(M) {} - NegativeNotPassedByValue(Movable *M) : M_(*M) {} - NegativeNotPassedByValue(const Movable *M) : M_(*M) {} - Movable M_; -}; - -struct Immovable { - Immovable(const Immovable &) = default; - Immovable(Immovable &&) = delete; -}; - -struct NegativeImmovableParameter { - NegativeImmovableParameter(Immovable I) : I_(I) {} - Immovable I_; -}; Copied: clang-tools-extra/trunk/test/clang-tidy/performance-inefficient-algorithm.cpp (from r319021, clang-tools-extra/trunk/test/clang-tidy/misc-inefficient-algorithm.cpp) URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/performance-inefficient-algorithm.cpp?p2=clang-tools-extra/trunk/test/clang-tidy/performance-inefficient-algorithm.cpp&p1=clang-tools-extra/trunk/test/clang-tidy/misc-inefficient-algorithm.cpp&r1=319021&r2=319023&rev=319023&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clang-tidy/misc-inefficient-algorithm.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/performance-inefficient-algorithm.cpp Mon Nov 27 05:06:28 2017 @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy %s misc-inefficient-algorithm %t +// RUN: %check_clang_tidy %s performance-inefficient-algorithm %t namespace std { template <typename T> struct less { @@ -78,7 +78,7 @@ template <typename T> void f(const T &t) int main() { std::set<int> s; auto it = std::find(s.begin(), s.end(), 43); - // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: this STL algorithm call should be replaced with a container method [misc-inefficient-algorithm] + // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: this STL algorithm call should be replaced with a container method [performance-inefficient-algorithm] // CHECK-FIXES: {{^ }}auto it = s.find(43);{{$}} auto c = count(s.begin(), s.end(), 43); // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: this STL algorithm call should be @@ -107,7 +107,7 @@ int main() { // CHECK-FIXES: {{^ }}msptr->find(46);{{$}} it = std::find(s.begin(), s.end(), 43, std::greater<int>()); - // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: different comparers used in the algorithm and the container [misc-inefficient-algorithm] + // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: different comparers used in the algorithm and the container [performance-inefficient-algorithm] FIND_IN_SET(s); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be Copied: clang-tools-extra/trunk/test/clang-tidy/performance-move-constructor-init.cpp (from r319021, clang-tools-extra/trunk/test/clang-tidy/misc-move-constructor-init.cpp) URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/performance-move-constructor-init.cpp?p2=clang-tools-extra/trunk/test/clang-tidy/performance-move-constructor-init.cpp&p1=clang-tools-extra/trunk/test/clang-tidy/misc-move-constructor-init.cpp&r1=319021&r2=319023&rev=319023&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clang-tidy/misc-move-constructor-init.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/performance-move-constructor-init.cpp Mon Nov 27 05:06:28 2017 @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy %s misc-move-constructor-init,modernize-pass-by-value %t -- \ +// RUN: %check_clang_tidy %s performance-move-constructor-init,modernize-pass-by-value %t -- \ // RUN: -config='{CheckOptions: \ // RUN: [{key: modernize-pass-by-value.ValuesOnly, value: 1}]}' \ // RUN: -- -std=c++11 -isystem %S/Inputs/Headers @@ -30,7 +30,7 @@ struct B { struct D : B { D() : B() {} D(const D &RHS) : B(RHS) {} - // CHECK-MESSAGES: :[[@LINE+3]]:16: warning: move constructor initializes base class by calling a copy constructor [misc-move-constructor-init] + // CHECK-MESSAGES: :[[@LINE+3]]:16: warning: move constructor initializes base class by calling a copy constructor [performance-move-constructor-init] // CHECK-MESSAGES: 26:3: note: copy constructor being called // CHECK-MESSAGES: 27:3: note: candidate move constructor here D(D &&RHS) : B(RHS) {} @@ -75,7 +75,7 @@ struct L : K { struct M { B Mem; - // CHECK-MESSAGES: :[[@LINE+1]]:16: warning: move constructor initializes class member by calling a copy constructor [misc-move-constructor-init] + // CHECK-MESSAGES: :[[@LINE+1]]:16: warning: move constructor initializes class member by calling a copy constructor [performance-move-constructor-init] M(M &&RHS) : Mem(RHS.Mem) {} }; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits