Skip to content

Commit

Permalink
[ADT] Slient warning related to memcpy of non trivially-copyable data
Browse files Browse the repository at this point in the history
  • Loading branch information
serge-sans-paille committed Oct 8, 2024
1 parent d368c69 commit 3f44807
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
3 changes: 2 additions & 1 deletion llvm/include/llvm/ADT/DenseMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@ class DenseMapBase : public DebugEpochBase {
const size_t NumBuckets = getNumBuckets();
if constexpr (std::is_trivially_copyable_v<KeyT> &&
std::is_trivially_copyable_v<ValueT>) {
memcpy(reinterpret_cast<void *>(Buckets), OtherBuckets,
memcpy(reinterpret_cast<void *>(Buckets),
reinterpret_cast<const void *>(OtherBuckets),
NumBuckets * sizeof(BucketT));
} else {
const KeyT EmptyKey = getEmptyKey();
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/ADT/Hashing.h
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ struct hash_combine_recursive_helper {
// with the variadic combine because that formation can have varying
// argument types.
size_t partial_store_size = buffer_end - buffer_ptr;
memcpy(buffer_ptr, &data, partial_store_size);
memcpy(buffer_ptr, reinterpret_cast<void *>(&data), partial_store_size);

// If the store fails, our buffer is full and ready to hash. We have to
// either initialize the hash state (on the first full buffer) or mix
Expand Down
11 changes: 6 additions & 5 deletions llvm/include/llvm/ADT/SmallVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -509,15 +509,15 @@ class SmallVectorTemplateBase<T, true> : public SmallVectorTemplateCommon<T> {
/// starting with "Dest", constructing elements into it as needed.
template <typename T1, typename T2>
static void uninitialized_copy(
T1 *I, T1 *E, T2 *Dest,
std::enable_if_t<std::is_same<std::remove_const_t<T1>, T2>::value> * =
nullptr) {
const T1 *I, const T1 *E, T2 *Dest,
std::enable_if_t<std::is_same<T1, T2>::value> * = nullptr) {
// Use memcpy for PODs iterated by pointers (which includes SmallVector
// iterators): std::uninitialized_copy optimizes to memmove, but we can
// use memcpy here. Note that I and E are iterators and thus might be
// invalid for memcpy if they are equal.
if (I != E)
memcpy(reinterpret_cast<void *>(Dest), I, (E - I) * sizeof(T));
memcpy(reinterpret_cast<void *>(Dest), reinterpret_cast<const void *>(I),
(E - I) * sizeof(T));
}

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

Expand Down

0 comments on commit 3f44807

Please sign in to comment.