From: Nico Weber Date: Thu, 28 Sep 2017 16:16:39 +0000 (+0000) Subject: Consolidate std::move() detection code. No behavior change. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9ecb2a666051a91774f4542f6684dd95618be2d0;p=clang Consolidate std::move() detection code. No behavior change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@314427 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 46d1ef5b1a..219bd1e5fd 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -2348,6 +2348,12 @@ public: SourceLocation getLocStart() const LLVM_READONLY; SourceLocation getLocEnd() const LLVM_READONLY; + bool isCallToStdMove() const { + const FunctionDecl* FD = getDirectCallee(); + return getNumArgs() == 1 && FD && FD->isInStdNamespace() && + FD->getIdentifier() && FD->getIdentifier()->isStr("move"); + } + static bool classof(const Stmt *T) { return T->getStmtClass() >= firstCallExprConstant && T->getStmtClass() <= lastCallExprConstant; diff --git a/lib/Analysis/Consumed.cpp b/lib/Analysis/Consumed.cpp index 19a85678bf..96edad0c30 100644 --- a/lib/Analysis/Consumed.cpp +++ b/lib/Analysis/Consumed.cpp @@ -749,8 +749,7 @@ void ConsumedStmtVisitor::VisitCallExpr(const CallExpr *Call) { // Special case for the std::move function. // TODO: Make this more specific. (Deferred) - if (Call->getNumArgs() == 1 && FunDecl->getNameAsString() == "move" && - FunDecl->isInStdNamespace()) { + if (Call->isCallToStdMove()) { copyInfo(Call->getArg(0), Call, CS_Consumed); return; } diff --git a/lib/Analysis/UninitializedValues.cpp b/lib/Analysis/UninitializedValues.cpp index 7d295a1f5c..5f11d8a2a3 100644 --- a/lib/Analysis/UninitializedValues.cpp +++ b/lib/Analysis/UninitializedValues.cpp @@ -440,16 +440,11 @@ static bool isPointerToConst(const QualType &QT) { void ClassifyRefs::VisitCallExpr(CallExpr *CE) { // Classify arguments to std::move as used. - if (CE->getNumArgs() == 1) { - if (FunctionDecl *FD = CE->getDirectCallee()) { - if (FD->isInStdNamespace() && FD->getIdentifier() && - FD->getIdentifier()->isStr("move")) { - // RecordTypes are handled in SemaDeclCXX.cpp. - if (!CE->getArg(0)->getType()->isRecordType()) - classify(CE->getArg(0), Use); - return; - } - } + if (CE->isCallToStdMove()) { + // RecordTypes are handled in SemaDeclCXX.cpp. + if (!CE->getArg(0)->getType()->isRecordType()) + classify(CE->getArg(0), Use); + return; } // If a value is passed by const pointer or by const reference to a function, diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index f1d3131b92..9a94900ce2 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -11765,9 +11765,7 @@ void Sema::DiagnoseSelfMove(const Expr *LHSExpr, const Expr *RHSExpr, return; // Check for a call to std::move - const FunctionDecl *FD = CE->getDirectCallee(); - if (!FD || !FD->isInStdNamespace() || !FD->getIdentifier() || - !FD->getIdentifier()->isStr("move")) + if (!CE->isCallToStdMove()) return; // Get argument from std::move diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index c99dbd944b..57f78cc03b 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -9993,14 +9993,9 @@ namespace { void VisitCallExpr(CallExpr *E) { // Treat std::move as a use. - if (E->getNumArgs() == 1) { - if (FunctionDecl *FD = E->getDirectCallee()) { - if (FD->isInStdNamespace() && FD->getIdentifier() && - FD->getIdentifier()->isStr("move")) { - HandleValue(E->getArg(0)); - return; - } - } + if (E->isCallToStdMove()) { + HandleValue(E->getArg(0)); + return; } Inherited::VisitCallExpr(E); diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index ff27e2d215..492694d07e 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -3390,14 +3390,9 @@ namespace { void VisitCallExpr(CallExpr *E) { // Treat std::move as a use. - if (E->getNumArgs() == 1) { - if (FunctionDecl *FD = E->getDirectCallee()) { - if (FD->isInStdNamespace() && FD->getIdentifier() && - FD->getIdentifier()->isStr("move")) { - HandleValue(E->getArg(0), false /*AddressOf*/); - return; - } - } + if (E->isCallToStdMove()) { + HandleValue(E->getArg(0), /*AddressOf=*/false); + return; } Inherited::VisitCallExpr(E);