public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/106904] New: Incorrect -Wstringop-overflow with partial memcpy() into a nested structure
@ 2022-09-11 22:47 zfigura at codeweavers dot com
  2022-09-11 22:51 ` [Bug tree-optimization/106904] " pinskia at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: zfigura at codeweavers dot com @ 2022-09-11 22:47 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106904
           Summary: Incorrect -Wstringop-overflow with partial memcpy()
                    into a nested structure
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zfigura at codeweavers dot com
  Target Milestone: ---

Created attachment 53562
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53562&action=edit
minimal test case

I encountered a warning while trying to compile 32-bit wine 7.17 with gcc 12.2,
specificially at this line here:

https://source.winehq.org/git/wine.git/blob/wine-7.17:/dlls/win32u/message.c#l359

The relevant code copies a smaller structure into a larger one of a different
type. (This may be a violation of aliasing rules, but adding
-fno-strict-aliasing doesn't change anything.)

I was able to reproduce this with a minimal test case. This is a very weird set
of conditions, but I couldn't seem to reduce this test case any further.
Changing the type of "ps" to "struct packed_windowpos" makes the error go away;
so does changing the first argument of the memcpy to "ps".

leslie@terabithia:~$ gcc --version
gcc (Debian 12.2.0-1) 12.2.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

leslie@terabithia:~$ gcc -m32 test.c -c -o test.o -Wall -O2
test.c: In function ‘func’:
test.c:26:5: warning: writing 8 bytes into a region of size 4
[-Wstringop-overflow=]
   26 |     __builtin_memcpy(&ps->wp, &wp, sizeof(wp));
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test.c:9:9: note: destination object ‘hwnd’ of size 4
    9 |     int hwnd;
      |         ^~~~

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

end of thread, other threads:[~2023-03-15 10:05 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-11 22:47 [Bug c/106904] New: Incorrect -Wstringop-overflow with partial memcpy() into a nested structure zfigura at codeweavers dot com
2022-09-11 22:51 ` [Bug tree-optimization/106904] " pinskia at gcc dot gnu.org
2022-09-11 22:52 ` zfigura at codeweavers dot com
2022-09-11 22:54 ` zfigura at codeweavers dot com
2022-09-13 15:30 ` [Bug tree-optimization/106904] [12/13 Regression] " pinskia at gcc dot gnu.org
2022-12-07 13:42 ` rguenth at gcc dot gnu.org
2022-12-11 13:35 ` cvs-commit at gcc dot gnu.org
2022-12-11 13:35 ` [Bug tree-optimization/106904] [12 " rguenth at gcc dot gnu.org
2022-12-11 17:40 ` zfigura at codeweavers dot com
2023-03-15  9:47 ` cvs-commit at gcc dot gnu.org
2023-03-15 10:05 ` rguenth 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).