From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 183053875DFD; Fri, 20 Mar 2020 11:23:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 183053875DFD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1584703431; bh=58gDivOgUkIut1mM9g7Z10jFqxk1gcwlmnsdYD7t4EA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=s79KbwT1kO1XScPWb5qv9jJrj5beKLyOsyEF+cyDlZQ2S2AYGY6G6LMHnAX//7a+F Tfnr0OtNFhXsq0rQ29amVqKKRsjJBp863DLD8dKwYg+G3vR9BpBQ+9Y/SM7SZs41HE mHn+LmpyckaVgQw+CuVhG2nBO8ydzcFcB7WHPQAI= From: "ch3root at openwall dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/92486] Wrong optimization: padding in structs is not copied even with memcpy Date: Fri, 20 Mar 2020 11:23:50 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 9.2.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: ch3root at openwall dot com X-Bugzilla-Status: NEW 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: Message-ID: In-Reply-To: References: 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Mar 2020 11:23:51 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D92486 --- Comment #18 from Alexander Cherepanov --- Adding a `memset` makes trunk fail too: ---------------------------------------------------------------------- #include #include struct s { char c; int i; }; __attribute__((noinline,noclone)) void f(struct s *p, struct s *q) { struct s w; memset(&w, 0, sizeof(struct s)); w =3D *q; memcpy(&w, q, sizeof(struct s)); *p =3D w; memcpy(p, &w, sizeof(struct s)); } int main() { struct s x; memset(&x, 1, sizeof(struct s)); struct s y; memset(&y, 2, sizeof(struct s)); f(&y, &x); for (unsigned char *p =3D (unsigned char *)&y; p < (unsigned char *)&y + sizeof(struct s); p++) printf("%d", *p); printf("\n"); } ---------------------------------------------------------------------- $ gcc -std=3Dc11 -pedantic -Wall -Wextra test.c && ./a.out 11111111 $ gcc -std=3Dc11 -pedantic -Wall -Wextra -O3 test.c && ./a.out 12221111 ---------------------------------------------------------------------- gcc x86-64 version: gcc (GCC) 10.0.1 20200320 (experimental) ----------------------------------------------------------------------=