[clang] [clang] Add lifetimebound attr to std::span/std::string_view constructor (PR #103716)

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 28 01:12:26 PDT 2024


================
@@ -216,6 +216,59 @@ void Sema::inferGslOwnerPointerAttribute(CXXRecordDecl *Record) {
   inferGslPointerAttribute(Record, Record);
 }
 
+void Sema::inferLifetimeBoundAttribute(FunctionDecl *FD) {
+  if (FD->getNumParams() == 0)
+    return;
+
+  if (unsigned BuiltinID = FD->getBuiltinID()) {
+    // Add lifetime attribute to std::move, std::fowrard et al.
+    switch (BuiltinID) {
+    case Builtin::BIaddressof:
+    case Builtin::BI__addressof:
+    case Builtin::BI__builtin_addressof:
+    case Builtin::BIas_const:
----------------
hokein wrote:

(The latter two cases are identical, we could potentially abstract a common function.)

I think this should be handled on a case-by-case basis, depending on the specific logic involved.  It seems fine to me have this small amount of duplication.

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


More information about the cfe-commits mailing list