[clang] [LifetimeSafety] Fix compiler crash with `static operator()` (PR #187853)

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 23 03:23:27 PDT 2026


================
@@ -655,6 +656,13 @@ void FactsGenerator::handleFunctionCall(const Expr *Call,
   // All arguments to a function are a use of the corresponding expressions.
   for (const Expr *Arg : Args)
     handleUse(Arg);
+
+  if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(Call);
+      OCE && OCE->getOperator() == OO_Call && FD->isStatic()) {
+    // Ignore first element
+    Args = Args.slice(1);
+  }
+
   handleInvalidatingCall(Call, FD, Args);
   handleMovedArgsInCall(FD, Args);
----------------
hokein wrote:

The crash occurs in the `handleMovedArgsInCall` method. Instead of shifting arguments at the caller level, I think it is better to fix the logic within `handleMovedArgsInCall` itself.

Looking at the current [implementation](https://github.com/llvm/llvm-project/blob/7c6996fc8fff8a24290b52b90ead246c7afdce65/clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp#L595) of `handleMovedArgsInCall`, it only shifts the argument list (skipping the function object) if the method is non-static. While this is correct for standard methods, it does not account for a static `operator()`.

For a static `operator()`, the function object is still provided as the first argument, similar to a non-static operator. This is an intended design choice (see https://github.com/llvm/llvm-project/pull/68485). 

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


More information about the cfe-commits mailing list