[llvm] 0712c57 - [ADT] Have ArrayRef::copy() return a MutableArrayRef

Jez Ng via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 18 11:56:25 PST 2022


Author: Jez Ng
Date: 2022-02-18T14:56:16-05:00
New Revision: 0712c575b90a7eb508bf43d15c38c1c0b0d69695

URL: https://github.com/llvm/llvm-project/commit/0712c575b90a7eb508bf43d15c38c1c0b0d69695
DIFF: https://github.com/llvm/llvm-project/commit/0712c575b90a7eb508bf43d15c38c1c0b0d69695.diff

LOG: [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

Added: 
    

Modified: 
    llvm/include/llvm/ADT/ArrayRef.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/ArrayRef.h b/llvm/include/llvm/ADT/ArrayRef.h
index b6896395dae8a..9af4232414e57 100644
--- a/llvm/include/llvm/ADT/ArrayRef.h
+++ b/llvm/include/llvm/ADT/ArrayRef.h
@@ -25,6 +25,7 @@
 #include <vector>
 
 namespace llvm {
+  template<typename T> 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<T> to it.
-    template <typename Allocator> ArrayRef<T> copy(Allocator &A) {
+    template <typename Allocator> MutableArrayRef<T> copy(Allocator &A) {
       T *Buff = A.template Allocate<T>(Length);
       std::uninitialized_copy(begin(), end(), Buff);
-      return ArrayRef<T>(Buff, Length);
+      return MutableArrayRef<T>(Buff, Length);
     }
 
     /// equals - Check for element-wise equality.


        


More information about the llvm-commits mailing list