================
@@ -105,6 +107,87 @@ bool implicitObjectParamIsLifetimeBound(const FunctionDecl 
*FD) {
   return isNormalAssignmentOperator(FD);
 }
 
+std::optional<LifetimeBoundParamInfo>
+getLifetimeBoundParamInfo(const FunctionDecl *FD, unsigned I) {
+  FD = getDeclWithMergedLifetimeBoundAttrs(FD);
+  if (!FD)
+    return std::nullopt;
+
+  const ParmVarDecl *PVD = nullptr;
+  if (const auto *Method = dyn_cast<CXXMethodDecl>(FD);
+      Method && Method->isInstance() && !isa<CXXConstructorDecl>(FD)) {
+    if (I == 0)
+      return implicitObjectParamIsLifetimeBound(Method)
+                 ? std::optional<LifetimeBoundParamInfo>(
+                       LifetimeBoundParamInfo(Method))
+                 : std::nullopt;
+    if ((I - 1) < Method->getNumParams())
+      PVD = Method->getParamDecl(I - 1);
+  } else if (I < FD->getNumParams()) {
+    PVD = FD->getParamDecl(I);
+  }
+
+  if (PVD && PVD->hasAttr<clang::LifetimeBoundAttr>())
+    return LifetimeBoundParamInfo(PVD);
+  return std::nullopt;
+}
+
+static bool isExprInCallArg(const Expr *Arg, const Expr *Source) {
+  if (!Arg || !Source)
+    return false;
+
+  Arg = Arg->IgnoreParenImpCasts();
+  Source = Source->IgnoreParenImpCasts();
+  if (Arg == Source || Arg->getSourceRange() == Source->getSourceRange())
+    return true;
+
+  for (const Stmt *Child : Arg->children())
+    if (const auto *ChildExpr = dyn_cast_or_null<Expr>(Child))
+      if (isExprInCallArg(ChildExpr, Source))
+        return true;
+
+  return false;
+}
+
+std::optional<LifetimeBoundParamInfo>
+getLifetimeBoundParamInfoForCallArg(const Expr *Call, const Expr *Source) {
----------------
iitianpushkar wrote:

Agreed. I will also follow this approach and update the patch accordingly.

https://github.com/llvm/llvm-project/pull/206337
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to