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

Haojian Wu via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 5 08:36:38 PST 2024


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

This helps catch dangling llvm::function_ref references, see #114950, #114949, #114808, #114789

>From 64a83a7341545d637ec81f2210f3e4837f91fdef Mon Sep 17 00:00:00 2001
From: Haojian Wu <hokein.wu at gmail.com>
Date: Tue, 5 Nov 2024 17:33:45 +0100
Subject: [PATCH] Add clang::lifetimebound annotation to llvm::function_ref

---
 llvm/include/llvm/ADT/STLFunctionalExtras.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

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,



More information about the llvm-commits mailing list