================
@@ -89,6 +89,67 @@ void findLifetimeBoundArgs(const CallExpr *Call,
                         BoundArgs);
 }
 
+bool isStdViewType(QualType T) {
+  return !T.isNull() &&
+         isStdView(T.getNonReferenceType()->getAsCXXRecordDecl());
+}
+
+void appendPresumedBorrowSources(const FunctionDecl *Callee,
+                                 ArrayRef<const Expr *> Args,
+                                 SmallVectorImpl<const Expr *> &BoundArgs) {
+  for (unsigned I = 0; I < Args.size(); ++I) {
+    QualType ParamType;
+    if (Callee && I < Callee->getNumParams())
+      ParamType = Callee->getParamDecl(I)->getType();
+    QualType ArgType = Args[I]->getType();
+    if ((!ParamType.isNull() && ParamType->isReferenceType()) ||
+        (!ArgType.isNull() && isView(ArgType)))
+      BoundArgs.push_back(Args[I]);
+  }
+}
+
+void findStdViewLifetimeBoundArgs(const CXXConstructExpr *Construct,
+                                  SmallVectorImpl<const Expr *> &BoundArgs) {
+  const auto *Ctor = Construct->getConstructor();
+  if (!Ctor || !isStdView(Ctor->getParent()))
+    return;
+  appendPresumedBorrowSources(
+      Ctor,
+      ArrayRef<const Expr *>(Construct->getArgs(), Construct->getNumArgs()),
+      BoundArgs);
+}
+
+void findStdViewLifetimeBoundArgs(const CallExpr *Call,
+                                  SmallVectorImpl<const Expr *> &BoundArgs) {
+  const FunctionDecl *Callee = Call->getDirectCallee();
+  if (!Callee)
+    return;
+
+  const Expr *ObjectArg = nullptr;
+  unsigned ArgOffset = 0;
+  if (isa<CXXOperatorCallExpr>(Call) && Callee->isCXXInstanceMember() &&
+      Call->getNumArgs()) {
+    ObjectArg = Call->getArg(0);
+    ArgOffset = 1;
+  } else if (auto *MemberCall = dyn_cast<CXXMemberCallExpr>(Call))
+    ObjectArg = MemberCall->getImplicitObjectArgument();
+
+  bool IsStdAccessor =
+      Callee->isInStdNamespace() &&
+      (safeGetName(Callee) == "data" || safeGetName(Callee) == "get");
+  if (!isStdViewType(Callee->getReturnType()) &&
+      !(ObjectArg && isStdViewType(ObjectArg->getType())) && !IsStdAccessor)
+    return;
+
+  if (ObjectArg)
+    BoundArgs.push_back(ObjectArg);
+  appendPresumedBorrowSources(
----------------
rniwa wrote:

Do we have a test case which tests these non-object arguments? Or multiple 
arguments being bound to different view types?

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

Reply via email to