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

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 23 06:08:26 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);
----------------
usx95 wrote:

> When calling a static operator() directly (with S()(...)), we also store S() in Args as the first argument, so all indexing is off by one.

I feel `handleMovedArgsInCall` is only one of the places where we see an off-by-one error. This should be an error in `handleFunctionCall` where we later iterate over the args and params.

So I suspect similar crash/bug if we handle this only in `handleMovedArgsInCall`. See https://godbolt.org/z/Mv5Edc7zc where we wrongly identifies 1 and 2 as dangling while 2 and 3 are actually dangling.

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


More information about the cfe-commits mailing list