diff --git a/lld/MachO/ICF.cpp b/lld/MachO/ICF.cpp --- a/lld/MachO/ICF.cpp +++ b/lld/MachO/ICF.cpp @@ -378,11 +378,10 @@ // mutable copy of the CFString and zero out the embedded addends before // performing any hashing / equality checks. if (isCfStringSection(isec)) { - uint8_t *copy = bAlloc().Allocate(isec->data.size()); - std::uninitialized_copy(isec->data.begin(), isec->data.end(), copy); + MutableArrayRef copy = isec->data.copy(bAlloc()); for (const Reloc &r : isec->relocs) - target->relocateOne(copy + r.offset, r, /*va=*/0, /*relocVA=*/0); - isec->data = ArrayRef(copy, isec->data.size()); + target->relocateOne(copy.data() + r.offset, r, /*va=*/0, /*relocVA=*/0); + isec->data = copy; } assert(isec->icfEqClass[0] == 0); // don't overwrite a unique ID! // Turn-on the top bit to guarantee that valid hashes have no collisions diff --git a/llvm/include/llvm/ADT/ArrayRef.h b/llvm/include/llvm/ADT/ArrayRef.h --- 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 @@ } // 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.