Skip to content

Commit 8d10e49

Browse files
committed
Add clang::lifetimebound annotation to ArrayRef constructors.
1 parent af872d5 commit 8d10e49

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

llvm/include/llvm/ADT/ArrayRef.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ namespace llvm {
7070
/*implicit*/ ArrayRef(std::nullopt_t) {}
7171

7272
/// Construct an ArrayRef from a single element.
73-
/*implicit*/ ArrayRef(const T &OneElt)
73+
/*implicit*/ ArrayRef(const T &OneElt LLVM_LIFETIME_BOUND)
7474
: Data(&OneElt), Length(1) {}
7575

7676
/// Construct an ArrayRef from a pointer and length.
@@ -103,7 +103,8 @@ namespace llvm {
103103

104104
/// Construct an ArrayRef from a C array.
105105
template <size_t N>
106-
/*implicit*/ constexpr ArrayRef(const T (&Arr)[N]) : Data(Arr), Length(N) {}
106+
/*implicit*/ constexpr ArrayRef(const T (&Arr LLVM_LIFETIME_BOUND)[N])
107+
: Data(Arr), Length(N) {}
107108

108109
/// Construct an ArrayRef from a std::initializer_list.
109110
#if LLVM_GNUC_PREREQ(9, 0, 0)

llvm/include/llvm/Support/Compiler.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,12 @@
413413
#define LLVM_GSL_POINTER
414414
#endif
415415

416+
#if LLVM_HAS_CPP_ATTRIBUTE(clang::lifetimebound)
417+
#define LLVM_LIFETIME_BOUND [[clang::lifetimebound]]
418+
#else
419+
#define LLVM_LLVM_LIFETIME_BOUND
420+
#endif
421+
416422
#if LLVM_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L
417423
#define LLVM_CTOR_NODISCARD [[nodiscard]]
418424
#else

0 commit comments

Comments
 (0)