From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 680173857BB7; Sun, 11 Sep 2022 22:47:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 680173857BB7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662936431; bh=JZzKxI0XYNlR58kKzR81Gj4DYtRvPtt42dSorVP4np8=; h=From:To:Subject:Date:From; b=bvnAPAfDTdFF91cK3ff4vAwCtVkYAzP5XdjzDtp/rCOe3Ft9Gvwnn61A5rBKBJ9If 3uYNNwK4CIS38L4X2ZbJ1oUh2pkMmpP9YW6DoomKIJo72Eibz8USTxYvHl3ALDZTRU bMkQ/9RWx2MtQcUTJD4FdmAUSZBU87ekL1SLuhz0= From: "zfigura at codeweavers dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/106904] New: Incorrect -Wstringop-overflow with partial memcpy() into a nested structure Date: Sun, 11 Sep 2022 22:47:11 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 12.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: zfigura at codeweavers dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106904 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=3D53562&action=3Dedit minimal test case I encountered a warning while trying to compile 32-bit wine 7.17 with gcc 1= 2.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 differe= nt 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 a= way; 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 =E2=80=98func=E2=80=99: test.c:26:5: warning: writing 8 bytes into a region of size 4 [-Wstringop-overflow=3D] 26 | __builtin_memcpy(&ps->wp, &wp, sizeof(wp)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ test.c:9:9: note: destination object =E2=80=98hwnd=E2=80=99 of size 4 9 | int hwnd; | ^~~~=