[llvm] Add clang::lifetimebound annotation to llvm::function_ref (PR #115019)

via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 5 08:37:17 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-adt

Author: Haojian Wu (hokein)

<details>
<summary>Changes</summary>

This helps catch dangling llvm::function_ref references, see #<!-- -->114950, #<!-- -->114949, #<!-- -->114808, #<!-- -->114789

---
Full diff: https://github.com/llvm/llvm-project/pull/115019.diff


1 Files Affected:

- (modified) llvm/include/llvm/ADT/STLFunctionalExtras.h (+2-1) 


``````````diff
diff --git a/llvm/include/llvm/ADT/STLFunctionalExtras.h b/llvm/include/llvm/ADT/STLFunctionalExtras.h
index 6f172504b3c167..3b9d40959d7142 100644
--- a/llvm/include/llvm/ADT/STLFunctionalExtras.h
+++ b/llvm/include/llvm/ADT/STLFunctionalExtras.h
@@ -16,6 +16,7 @@
 #define LLVM_ADT_STLFUNCTIONALEXTRAS_H
 
 #include "llvm/ADT/STLForwardCompat.h"
+#include "llvm/Support/Compiler.h"
 
 #include <cstdint>
 #include <type_traits>
@@ -52,7 +53,7 @@ class function_ref<Ret(Params...)> {
 
   template <typename Callable>
   function_ref(
-      Callable &&callable,
+      Callable &&callable LLVM_LIFETIME_BOUND,
       // This is not the copy-constructor.
       std::enable_if_t<!std::is_same<remove_cvref_t<Callable>,
                                      function_ref>::value> * = nullptr,

``````````

</details>


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


More information about the llvm-commits mailing list