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

Gábor Horváth via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 14 05:51:58 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:
----------------
Xazax-hun wrote:

I start to have the feeling we are writing code like this over and over again.
Some examples:
https://github.com/llvm/llvm-project/blob/df57833ea8a3f527b7941576b4a130ddd4361e61/clang/lib/Analysis/BodyFarm.cpp#L718
https://github.com/llvm/llvm-project/blob/df57833ea8a3f527b7941576b4a130ddd4361e61/clang/lib/AST/ExprConstant.cpp#L8763

But there are more, and I always wonder if they can get out of sync. I wonder if this is time to introduce some helper functions that can be reused. 

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


More information about the cfe-commits mailing list