[Bug target/114615] spurious warning on mingw-w64: 'memcpy' reading 4 or more bytes from a region of size 2 with std::wstring{L""} and -flto -O1 [Wstringop-overread]
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114615 --- Comment #4 from Andrew Pinski --- (In reply to Jonathan Wakely from comment #3) > The dumb part is that __n here comes from wcslen(__s2), so the compiler is > able to track that __s2 is only two bytes, but not capable of tracking that > __n == 0. > > Specifically, __n is (__s2 + wcslen(__s2)) - __s2 which is just wcslen(L"") > which is 0. I dont think we fold/track wide_t builtins at all ...
[Bug target/114615] spurious warning on mingw-w64: 'memcpy' reading 4 or more bytes from a region of size 2 with std::wstring{L""} and -flto -O1 [Wstringop-overread]
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114615 --- Comment #3 from Jonathan Wakely --- The dumb part is that __n here comes from wcslen(__s2), so the compiler is able to track that __s2 is only two bytes, but not capable of tracking that __n == 0. Specifically, __n is (__s2 + wcslen(__s2)) - __s2 which is just wcslen(L"") which is 0.
[Bug target/114615] spurious warning on mingw-w64: 'memcpy' reading 4 or more bytes from a region of size 2 with std::wstring{L""} and -flto -O1 [Wstringop-overread]
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114615 Jonathan Wakely changed: What|Removed |Added Keywords||diagnostic --- Comment #2 from Jonathan Wakely --- Or jump threading is splitting the code into two branches for N <= 1 and N >= 2, and then warning that the N >= 2 case would read past the end of the source buffer. But that case never actually happens. The constructor calls _M_construct which goes to: static void _S_copy(_CharT* __d, const _CharT* __s, size_type __n) { if (__n == 1) traits_type::assign(*__d, *__s); else traits_type::copy(__d, __s, __n); } The N == 1 case is handled here, then char_traits::copy does: static _GLIBCXX20_CONSTEXPR char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) { if (__n == 0) return __s1; #if __cplusplus >= 202002L if (std::__is_constant_evaluated()) return __gnu_cxx::char_traits::copy(__s1, __s2, __n); #endif return wmemcpy(__s1, __s2, __n); } So the N == 0 case is also handled here, so we only use wmemcpy for N >= 2. And that would indeed read N * sizeof(wchar_t), i.e. 4 or more bytes, from L"" which is only 2 bytes. But it's unreachable, because we take the if (__n == 0) branch.
[Bug target/114615] spurious warning on mingw-w64: 'memcpy' reading 4 or more bytes from a region of size 2 with std::wstring{L""} and -flto -O1 [Wstringop-overread]
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114615 Andrew Pinski changed: What|Removed |Added Target||x86_64-w64-mingw32 Component|tree-optimization |target --- Comment #1 from Andrew Pinski --- -municode defines UNICODE . Maybe there is some mismatching of wchar_t somewhere ...