[clang-tools-extra] [clang-tidy] Improve performance-use-std-move in presence of control-flow (PR #184136)

via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 8 01:59:38 PST 2026


================
@@ -112,13 +148,36 @@ void UseStdMoveCheck::check(const MatchFinder::MatchResult &Result) {
             << FixItHint::CreateReplacement(
                    AssignValue->getLocation(),
                    ("std::move(" + AssignValueName + ")").str());
+        ReferencesAssignedValue = true;
         break;
       }
-      // The reference is being referenced after the assignment, bail out.
+
+      // The reference is being referenced after the assignment.
       if (!allDeclRefExprs(*cast<VarDecl>(AssignValue->getDecl()), *EltStmt,
                            *Result.Context)
-               .empty())
+               .empty()) {
+        ReferencesAssignedValue = true;
         break;
+      }
+    }
+    if (ReferencesAssignedValue) {
+      // Cancel all predecessors.
+      for (const auto &S : B->preds()) {
+        if (!S.isReachable())
+          continue;
+        CFGState.find(&*S)->second.Ready = false;
+      }
+    } else {
+      // Or process the ready ones.
+      for (const auto &S : B->preds()) {
+        if (!S.isReachable())
+          continue;
+        auto &W = CFGState.find(&*S)->second;
+        if (W.Ready) {
+          if (--W.RemainingSuccessors == 0 && S.isReachable())
----------------
zeyi2 wrote:

`S.isReachable()` may be redundant here? We already checked it before by:
```cpp
if (!S.isReachable()) continue;
```

https://github.com/llvm/llvm-project/pull/184136


More information about the cfe-commits mailing list