[clang] [clang][analyzer] Detect use-after-move for 3-arg std::move (PR #196602)

Gábor Horváth via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 1 01:34:05 PDT 2026


================
@@ -495,6 +507,78 @@ void MoveChecker::checkPostCall(const CallEvent &Call,
   assert(!C.isDifferent() && "Should not have made transitions on this path!");
 }
 
+bool MoveChecker::evalCall(const CallEvent &Call, CheckerContext &C) const {
+
+  const auto *CE = dyn_cast_if_present<CallExpr>(Call.getOriginExpr());
+  if (!CE)
+    return false;
+
+  ProgramStateRef State = C.getState();
+
+  if (!StdMoveCall.matches(Call))
+    return false;
+
+  const auto *BeginCall =
----------------
Xazax-hun wrote:

Usually, we try to avoid matching the AST like this. It can make the analysis fragile.

E.g.:
```
std::move(c.begin(), ... );
```
vs
```
auto b = c.begin();
std::move(c, ...);
```

I wonder if the information what iterator belongs to what container is already stored in one of the iterator checkers. If that's the case, maybe we could depend on a modeling checker that calculates this information and use that state instead of relying on the AST. 

Alternatively, once we understand `lifetimebound` annotation, that same info can be used to infer what container does the iterator belong to. 

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


More information about the cfe-commits mailing list