[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

Boaz Brickner via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 15 06:09:41 PST 2024


================
@@ -3229,6 +3230,52 @@ void Sema::CheckArgAlignment(SourceLocation Loc, NamedDecl *FDecl,
         << ParamName << (FDecl != nullptr) << FDecl;
 }
 
+void Sema::checkLifetimeCaptureBy(FunctionDecl *FD, bool IsMemberFunction,
+                                  const Expr *ThisArg,
+                                  ArrayRef<const Expr *> Args) {
+  auto GetArgAt = [&](int Idx) -> Expr * {
+    if (Idx == LifetimeCaptureByAttr::GLOBAL ||
+        Idx == LifetimeCaptureByAttr::UNKNOWN)
+      return nullptr;
+    if (IsMemberFunction && Idx == 0)
+      return const_cast<Expr *>(ThisArg);
+    return const_cast<Expr *>(Args[Idx - int(IsMemberFunction)]);
----------------
bricknerb wrote:

How about merging the two return statements to one to share const cast?

return const_cast<Expr *>(IsMemberFunction && Idx == 0 ? ... : ...);

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


More information about the cfe-commits mailing list