[clang] [llvm] [llvm] Add lifetimebound to llvm::sys::path::filename, etc. (PR #122890)

Utkarsh Saxena via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 14 03:52:43 PST 2025


https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/122890

>From c660f891b2c54c795fea58807be4405710e7a6b0 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena <usx at google.com>
Date: Wed, 8 Jan 2025 13:42:11 +0000
Subject: [PATCH 1/2] [clang] Infer capture_by for insert_or_assign

---
 clang/lib/Sema/SemaAttr.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp
index 44485e71d57a01..42aa68d2905c03 100644
--- a/clang/lib/Sema/SemaAttr.cpp
+++ b/clang/lib/Sema/SemaAttr.cpp
@@ -307,8 +307,8 @@ void Sema::inferLifetimeCaptureByAttribute(FunctionDecl *FD) {
       Annotate(MD);
     return;
   }
-  static const llvm::StringSet<> CapturingMethods{"insert", "push",
-                                                  "push_front", "push_back"};
+  static const llvm::StringSet<> CapturingMethods{
+      "insert", "insert_or_assign", "push", "push_front", "push_back"};
   if (!CapturingMethods.contains(MD->getName()))
     return;
   Annotate(MD);

>From a63d4aa088fc8b58fd56eb7a0881106da88d3ab5 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena <usx at google.com>
Date: Tue, 14 Jan 2025 11:50:57 +0000
Subject: [PATCH 2/2] [llvm] Add lifetimebound to llvm::sys::path::filename,
 etc.

---
 llvm/include/llvm/Support/Path.h | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/llvm/include/llvm/Support/Path.h b/llvm/include/llvm/Support/Path.h
index ce69f32b6cc81b..bbf1c5037e6751 100644
--- a/llvm/include/llvm/Support/Path.h
+++ b/llvm/include/llvm/Support/Path.h
@@ -119,22 +119,24 @@ class reverse_iterator
 /// Get begin iterator over \a path.
 /// @param path Input path.
 /// @returns Iterator initialized with the first component of \a path.
-const_iterator begin(StringRef path, Style style = Style::native);
+const_iterator begin(StringRef path LLVM_LIFETIME_BOUND,
+                     Style style = Style::native);
 
 /// Get end iterator over \a path.
 /// @param path Input path.
 /// @returns Iterator initialized to the end of \a path.
-const_iterator end(StringRef path);
+const_iterator end(StringRef path LLVM_LIFETIME_BOUND);
 
 /// Get reverse begin iterator over \a path.
 /// @param path Input path.
 /// @returns Iterator initialized with the first reverse component of \a path.
-reverse_iterator rbegin(StringRef path, Style style = Style::native);
+reverse_iterator rbegin(StringRef path LLVM_LIFETIME_BOUND,
+                        Style style = Style::native);
 
 /// Get reverse end iterator over \a path.
 /// @param path Input path.
 /// @returns Iterator initialized to the reverse end of \a path.
-reverse_iterator rend(StringRef path);
+reverse_iterator rend(StringRef path LLVM_LIFETIME_BOUND);
 
 /// @}
 /// @name Lexical Modifiers
@@ -199,7 +201,7 @@ bool replace_path_prefix(SmallVectorImpl<char> &Path, StringRef OldPrefix,
 ///
 /// @param path Input path.
 /// @result The cleaned-up \a path.
-StringRef remove_leading_dotslash(StringRef path, Style style = Style::native);
+StringRef remove_leading_dotslash(StringRef path LLVM_LIFETIME_BOUND, Style style = Style::native);
 
 /// In-place remove any './' and optionally '../' components from a path.
 ///
@@ -295,7 +297,7 @@ std::string convert_to_slash(StringRef path, Style style = Style::native);
 ///
 /// @param path Input path.
 /// @result The root name of \a path if it has one, otherwise "".
-StringRef root_name(StringRef path, Style style = Style::native);
+StringRef root_name(StringRef path LLVM_LIFETIME_BOUND, Style style = Style::native);
 
 /// Get root directory.
 ///
@@ -308,7 +310,7 @@ StringRef root_name(StringRef path, Style style = Style::native);
 /// @param path Input path.
 /// @result The root directory of \a path if it has one, otherwise
 ///               "".
-StringRef root_directory(StringRef path, Style style = Style::native);
+StringRef root_directory(StringRef path LLVM_LIFETIME_BOUND, Style style = Style::native);
 
 /// Get root path.
 ///
@@ -316,7 +318,7 @@ StringRef root_directory(StringRef path, Style style = Style::native);
 ///
 /// @param path Input path.
 /// @result The root path of \a path if it has one, otherwise "".
-StringRef root_path(StringRef path, Style style = Style::native);
+StringRef root_path(StringRef path LLVM_LIFETIME_BOUND, Style style = Style::native);
 
 /// Get relative path.
 ///
@@ -328,7 +330,7 @@ StringRef root_path(StringRef path, Style style = Style::native);
 ///
 /// @param path Input path.
 /// @result The path starting after root_path if one exists, otherwise "".
-StringRef relative_path(StringRef path, Style style = Style::native);
+StringRef relative_path(StringRef path LLVM_LIFETIME_BOUND, Style style = Style::native);
 
 /// Get parent path.
 ///
@@ -340,7 +342,8 @@ StringRef relative_path(StringRef path, Style style = Style::native);
 ///
 /// @param path Input path.
 /// @result The parent path of \a path if one exists, otherwise "".
-StringRef parent_path(StringRef path, Style style = Style::native);
+StringRef parent_path(StringRef path LLVM_LIFETIME_BOUND,
+                      Style style = Style::native);
 
 /// Get filename.
 ///
@@ -354,7 +357,7 @@ StringRef parent_path(StringRef path, Style style = Style::native);
 /// @param path Input path.
 /// @result The filename part of \a path. This is defined as the last component
 ///         of \a path. Similar to the POSIX "basename" utility.
-StringRef filename(StringRef path, Style style = Style::native);
+StringRef filename(StringRef path LLVM_LIFETIME_BOUND, Style style = Style::native);
 
 /// Get stem.
 ///
@@ -372,7 +375,7 @@ StringRef filename(StringRef path, Style style = Style::native);
 ///
 /// @param path Input path.
 /// @result The stem of \a path.
-StringRef stem(StringRef path, Style style = Style::native);
+StringRef stem(StringRef path LLVM_LIFETIME_BOUND, Style style = Style::native);
 
 /// Get extension.
 ///
@@ -388,7 +391,8 @@ StringRef stem(StringRef path, Style style = Style::native);
 ///
 /// @param path Input path.
 /// @result The extension of \a path.
-StringRef extension(StringRef path, Style style = Style::native);
+StringRef extension(StringRef path LLVM_LIFETIME_BOUND,
+                    Style style = Style::native);
 
 /// Check whether the given char is a path separator on the host OS.
 ///



More information about the llvm-commits mailing list