[clang] [compiler-rt] [libcxx] [llvm] [clang] Warn about memset/memcpy to NonTriviallyCopyable types (PR #111434)
Carlos Galvez via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 22 05:23:48 PDT 2024
================
@@ -102,7 +102,7 @@ struct __aliasing_iterator_wrapper {
_LIBCPP_HIDE_FROM_ABI _Alias operator*() const _NOEXCEPT {
_Alias __val;
- __builtin_memcpy(&__val, std::__to_address(__base_), sizeof(value_type));
+ __builtin_memcpy(&__val, static_cast<const void*>(std::__to_address(__base_)), sizeof(value_type));
----------------
carlosgalvezp wrote:
Also, [[intro.object]#8.4](https://eel.is/c++draft/intro.object#8.4) says:
> An object of trivially copyable or standard-layout type ([[basic.types.general]](https://eel.is/c++draft/basic.types.general)) shall occupy contiguous bytes of storage[.](https://eel.is/c++draft/intro.object#8.sentence-5)
`std::memcpy` assumes the bytes of the object are laid contiguously in memory, so I guess that's a requirement that also applies to the `src` parameter, not just `dst`.
Not saying we should enforce this in this warning, but this could explain the requirement for TriviallyCopyable.
https://github.com/llvm/llvm-project/pull/111434
More information about the llvm-commits
mailing list