public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/114615] New: 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]
@ 2024-04-05 22:18 bugzilla.gcc.simon at arlott dot org
  2024-04-05 22:24 ` [Bug target/114615] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: bugzilla.gcc.simon at arlott dot org @ 2024-04-05 22:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114615

            Bug ID: 114615
           Summary: 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]
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bugzilla.gcc.simon at arlott dot org
  Target Milestone: ---

This only happens on MinGW, when compiling with -flto, -municode and
optimisations. I get a spurious warning and it fails to optimise away the
constructor/destructor:

$ x86_64-w64-mingw32-g++ -o test.exe test.cc -flto -municode -O1
In function ‘wmemcpy’,
    inlined from ‘copy’ at
/usr/lib/gcc/x86_64-w64-mingw32/12-win32/include/c++/bits/char_traits.h:558:16,
    inlined from ‘_S_copy’ at
/usr/lib/gcc/x86_64-w64-mingw32/12-win32/include/c++/bits/basic_string.h:423:21,
    inlined from ‘_S_copy_chars’ at
/usr/lib/gcc/x86_64-w64-mingw32/12-win32/include/c++/bits/basic_string.h:477:16,
    inlined from ‘_M_construct’ at
/usr/lib/gcc/x86_64-w64-mingw32/12-win32/include/c++/bits/basic_string.tcc:243:21,
    inlined from ‘__ct_comp ’ at
/usr/lib/gcc/x86_64-w64-mingw32/12-win32/include/c++/bits/basic_string.h:642:14,
    inlined from ‘wmain’ at test.cc:5:23:
/usr/share/mingw-w64/include/wchar.h:1502:31: warning: ‘memcpy’ reading 4 or
more bytes from a region of size 2 [-Wstringop-overread]
 1502 |     return (wchar_t *) memcpy (_S1,_S2,_N*sizeof(wchar_t));
      |                               ^

test.cc:
#include <windows.h>
#include <string>

int wmain(int argc, wchar_t *argv[], wchar_t *envp[]) {
        std::wstring test{L""};
        return 0;
}

I can reproduce it here on MinGW GCC 12.1.0 and 12.2.0:
https://godbolt.org/z/dv7Pb8nx4 (the MinGW GCC 13 compiler on there is
currently not working at all)

MinGW GCC 11.3.0 is ok.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-04-08 21:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-05 22:18 [Bug tree-optimization/114615] New: 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] bugzilla.gcc.simon at arlott dot org
2024-04-05 22:24 ` [Bug target/114615] " pinskia at gcc dot gnu.org
2024-04-08 10:54 ` redi at gcc dot gnu.org
2024-04-08 10:58 ` redi at gcc dot gnu.org
2024-04-08 21:04 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).