From: Jez Ng Date: Fri, 18 Feb 2022 19:56:16 +0000 (-0500) Subject: [ADT] Have ArrayRef::copy() return a MutableArrayRef X-Git-Tag: upstream/15.0.7~15883 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0712c575b90a7eb508bf43d15c38c1c0b0d69695;p=platform%2Fupstream%2Fllvm.git [ADT] Have ArrayRef::copy() return a MutableArrayRef The allocated memory itself is mutable, so let's expose that to the caller. LLD has a use case for this. Reviewed By: MaskRay, #lld-macho Differential Revision: https://reviews.llvm.org/D120144 --- diff --git a/llvm/include/llvm/ADT/ArrayRef.h b/llvm/include/llvm/ADT/ArrayRef.h index b689639..9af4232 100644 --- a/llvm/include/llvm/ADT/ArrayRef.h +++ b/llvm/include/llvm/ADT/ArrayRef.h @@ -25,6 +25,7 @@ #include namespace llvm { + template class LLVM_NODISCARD MutableArrayRef; /// ArrayRef - Represent a constant reference to an array (0 or more elements /// consecutively in memory), i.e. a start pointer and a length. It allows @@ -175,10 +176,10 @@ namespace llvm { } // copy - Allocate copy in Allocator and return ArrayRef to it. - template ArrayRef copy(Allocator &A) { + template MutableArrayRef copy(Allocator &A) { T *Buff = A.template Allocate(Length); std::uninitialized_copy(begin(), end(), Buff); - return ArrayRef(Buff, Length); + return MutableArrayRef(Buff, Length); } /// equals - Check for element-wise equality.