]> granicus.if.org Git - clang/commitdiff
Consolidate std::move() detection code. No behavior change.
authorNico Weber <nicolasweber@gmx.de>
Thu, 28 Sep 2017 16:16:39 +0000 (16:16 +0000)
committerNico Weber <nicolasweber@gmx.de>
Thu, 28 Sep 2017 16:16:39 +0000 (16:16 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@314427 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Expr.h
lib/Analysis/Consumed.cpp
lib/Analysis/UninitializedValues.cpp
lib/Sema/SemaChecking.cpp
lib/Sema/SemaDecl.cpp
lib/Sema/SemaDeclCXX.cpp

index 46d1ef5b1a39531053774ef709da355fb5a55cf6..219bd1e5fd94bb6508e32e9ea1c7cb4493a3f489 100644 (file)
@@ -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;
index 19a85678bf29b10d595b4442eda85abe8d81cac8..96edad0c3019fe4ea732bbd8b2c1971bef1efd0c 100644 (file)
@@ -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;
   }
index 7d295a1f5cb6a6e9b926226e4f886a0774c77345..5f11d8a2a36b5eb1a3f47d4c1b42275c89b7d0bf 100644 (file)
@@ -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,
index f1d3131b9296bde769f6e41d96d49708a256da18..9a94900ce2f035d87d4ff55f083a3216ae8a110f 100644 (file)
@@ -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
index c99dbd944b052f603ff344ff1758566fb137c6c9..57f78cc03ba2dda18aa18f1217e521c44867f20b 100644 (file)
@@ -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);
index ff27e2d2159bfae3ba1c4aacdea740f56551a0ad..492694d07ef08c3a3c20753a572cc6ac58fa62c7 100644 (file)
@@ -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);