Skip to content

Commit 31be3da

Browse files
[ADT] Silent warning related to memcpy of non trivially-copyable data
1 parent b651491 commit 31be3da

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

llvm/include/llvm/ADT/DenseMap.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,8 @@ class DenseMapBase : public DebugEpochBase {
442442
const size_t NumBuckets = getNumBuckets();
443443
if constexpr (std::is_trivially_copyable_v<KeyT> &&
444444
std::is_trivially_copyable_v<ValueT>) {
445-
memcpy(reinterpret_cast<void *>(Buckets), OtherBuckets,
445+
memcpy(reinterpret_cast<void *>(Buckets),
446+
reinterpret_cast<const void *>(OtherBuckets),
446447
NumBuckets * sizeof(BucketT));
447448
} else {
448449
const KeyT EmptyKey = getEmptyKey();

llvm/include/llvm/ADT/Hashing.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ struct hash_combine_recursive_helper {
508508
// with the variadic combine because that formation can have varying
509509
// argument types.
510510
size_t partial_store_size = buffer_end - buffer_ptr;
511-
memcpy(buffer_ptr, &data, partial_store_size);
511+
memcpy(buffer_ptr, reinterpret_cast<void *>(&data), partial_store_size);
512512

513513
// If the store fails, our buffer is full and ready to hash. We have to
514514
// either initialize the hash state (on the first full buffer) or mix

llvm/include/llvm/ADT/SmallVector.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -509,15 +509,15 @@ class SmallVectorTemplateBase<T, true> : public SmallVectorTemplateCommon<T> {
509509
/// starting with "Dest", constructing elements into it as needed.
510510
template <typename T1, typename T2>
511511
static void uninitialized_copy(
512-
T1 *I, T1 *E, T2 *Dest,
513-
std::enable_if_t<std::is_same<std::remove_const_t<T1>, T2>::value> * =
514-
nullptr) {
512+
const T1 *I, const T1 *E, T2 *Dest,
513+
std::enable_if_t<std::is_same<T1, T2>::value> * = nullptr) {
515514
// Use memcpy for PODs iterated by pointers (which includes SmallVector
516515
// iterators): std::uninitialized_copy optimizes to memmove, but we can
517516
// use memcpy here. Note that I and E are iterators and thus might be
518517
// invalid for memcpy if they are equal.
519518
if (I != E)
520-
memcpy(reinterpret_cast<void *>(Dest), I, (E - I) * sizeof(T));
519+
memcpy(reinterpret_cast<void *>(Dest), reinterpret_cast<const void *>(I),
520+
(E - I) * sizeof(T));
521521
}
522522

523523
/// Double the size of the allocated memory, guaranteeing space for at
@@ -560,7 +560,8 @@ class SmallVectorTemplateBase<T, true> : public SmallVectorTemplateCommon<T> {
560560
public:
561561
void push_back(ValueParamT Elt) {
562562
const T *EltPtr = reserveForParamAndGetAddress(Elt);
563-
memcpy(reinterpret_cast<void *>(this->end()), EltPtr, sizeof(T));
563+
memcpy(reinterpret_cast<void *>(this->end()),
564+
reinterpret_cast<const void *>(EltPtr), sizeof(T));
564565
this->set_size(this->size() + 1);
565566
}
566567

0 commit comments

Comments
 (0)