summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/misc/MoveConstantArgumentCheck.cpp
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2017-11-28 16:41:03 +0000
committerAlexander Kornienko <alexfh@google.com>2017-11-28 16:41:03 +0000
commit1bfcba8ceaf3c8dc9b2443e61b8649c3506ca2f0 (patch)
treeac2883c5617a84a282e431ec048900ff39a7178d /clang-tools-extra/clang-tidy/misc/MoveConstantArgumentCheck.cpp
parent14230e02ffe1a42b509360d8d8b687ebc961a75e (diff)
downloadbcm5719-llvm-1bfcba8ceaf3c8dc9b2443e61b8649c3506ca2f0.tar.gz
bcm5719-llvm-1bfcba8ceaf3c8dc9b2443e61b8649c3506ca2f0.zip
[clang-tidy] Move more checks from misc- to performance-
Summary: rename_check.py misc-move-const-arg performance-move-const-arg rename_check.py misc-noexcept-move-constructor performance-noexcept-move-constructor Reviewers: hokein, xazax.hun Reviewed By: xazax.hun Subscribers: rnkovacs, klimek, mgorny, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D40507 llvm-svn: 319183
Diffstat (limited to 'clang-tools-extra/clang-tidy/misc/MoveConstantArgumentCheck.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/misc/MoveConstantArgumentCheck.cpp122
1 files changed, 0 insertions, 122 deletions
diff --git a/clang-tools-extra/clang-tidy/misc/MoveConstantArgumentCheck.cpp b/clang-tools-extra/clang-tidy/misc/MoveConstantArgumentCheck.cpp
deleted file mode 100644
index 196d982eff1..00000000000
--- a/clang-tools-extra/clang-tidy/misc/MoveConstantArgumentCheck.cpp
+++ /dev/null
@@ -1,122 +0,0 @@
-//===--- MoveConstantArgumentCheck.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 "MoveConstantArgumentCheck.h"
-
-#include "clang/Lex/Lexer.h"
-
-using namespace clang::ast_matchers;
-
-namespace clang {
-namespace tidy {
-namespace misc {
-
-static void ReplaceCallWithArg(const CallExpr *Call, DiagnosticBuilder &Diag,
- const SourceManager &SM,
- const LangOptions &LangOpts) {
- const Expr *Arg = Call->getArg(0);
-
- CharSourceRange BeforeArgumentsRange = Lexer::makeFileCharRange(
- CharSourceRange::getCharRange(Call->getLocStart(), Arg->getLocStart()),
- SM, LangOpts);
- CharSourceRange AfterArgumentsRange = Lexer::makeFileCharRange(
- CharSourceRange::getCharRange(Call->getLocEnd(),
- Call->getLocEnd().getLocWithOffset(1)),
- SM, LangOpts);
-
- if (BeforeArgumentsRange.isValid() && AfterArgumentsRange.isValid()) {
- Diag << FixItHint::CreateRemoval(BeforeArgumentsRange)
- << FixItHint::CreateRemoval(AfterArgumentsRange);
- }
-}
-
-void MoveConstantArgumentCheck::storeOptions(
- ClangTidyOptions::OptionMap &Opts) {
- Options.store(Opts, "CheckTriviallyCopyableMove", CheckTriviallyCopyableMove);
-}
-
-void MoveConstantArgumentCheck::registerMatchers(MatchFinder *Finder) {
- if (!getLangOpts().CPlusPlus)
- return;
-
- auto MoveCallMatcher =
- callExpr(callee(functionDecl(hasName("::std::move"))), argumentCountIs(1),
- unless(isInTemplateInstantiation()))
- .bind("call-move");
-
- Finder->addMatcher(MoveCallMatcher, this);
-
- auto ConstParamMatcher = forEachArgumentWithParam(
- MoveCallMatcher, parmVarDecl(hasType(references(isConstQualified()))));
-
- Finder->addMatcher(callExpr(ConstParamMatcher).bind("receiving-expr"), this);
- Finder->addMatcher(cxxConstructExpr(ConstParamMatcher).bind("receiving-expr"),
- this);
-}
-
-void MoveConstantArgumentCheck::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);
- SourceManager &SM = Result.Context->getSourceManager();
-
- CharSourceRange MoveRange =
- CharSourceRange::getCharRange(CallMove->getSourceRange());
- CharSourceRange FileMoveRange =
- Lexer::makeFileCharRange(MoveRange, SM, getLangOpts());
- if (!FileMoveRange.isValid())
- return;
-
- bool IsConstArg = Arg->getType().isConstQualified();
- bool IsTriviallyCopyable =
- Arg->getType().isTriviallyCopyableType(*Result.Context);
-
- if (IsConstArg || IsTriviallyCopyable) {
- if (const CXXRecordDecl *R = Arg->getType()->getAsCXXRecordDecl()) {
- // According to [expr.prim.lambda]p3, "whether the closure type is
- // trivially copyable" property can be changed by the implementation of
- // the language, so we shouldn't rely on it when issuing diagnostics.
- if (R->isLambda())
- return;
- // Don't warn when the type is not copyable.
- for (const auto *Ctor : R->ctors()) {
- if (Ctor->isCopyConstructor() && Ctor->isDeleted())
- return;
- }
- }
-
- if (!IsConstArg && IsTriviallyCopyable && !CheckTriviallyCopyableMove)
- return;
-
- bool IsVariable = isa<DeclRefExpr>(Arg);
- const auto *Var =
- IsVariable ? dyn_cast<DeclRefExpr>(Arg)->getDecl() : nullptr;
- auto Diag = diag(FileMoveRange.getBegin(),
- "std::move of the %select{|const }0"
- "%select{expression|variable %4}1 "
- "%select{|of the trivially-copyable type %5 }2"
- "has no effect; remove std::move()"
- "%select{| or make the variable non-const}3")
- << IsConstArg << IsVariable << IsTriviallyCopyable
- << (IsConstArg && IsVariable && !IsTriviallyCopyable) << Var
- << Arg->getType();
-
- ReplaceCallWithArg(CallMove, Diag, SM, getLangOpts());
- } else if (ReceivingExpr) {
- auto Diag = diag(FileMoveRange.getBegin(),
- "passing result of std::move() as a const reference "
- "argument; no move will actually happen");
-
- ReplaceCallWithArg(CallMove, Diag, SM, getLangOpts());
- }
-}
-
-} // namespace misc
-} // namespace tidy
-} // namespace clang
OpenPOWER on IntegriCloud