public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "ch3root at openwall dot com" <gcc-bugzilla@gcc.gnu.org> 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 [thread overview] Message-ID: <bug-92486-4-uAbgeRZ9q3@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-92486-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92486 --- Comment #18 from Alexander Cherepanov <ch3root at openwall dot com> --- Adding a `memset` makes trunk fail too: ---------------------------------------------------------------------- #include <string.h> #include <stdio.h> 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 = *q; memcpy(&w, q, sizeof(struct s)); *p = 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 = (unsigned char *)&y; p < (unsigned char *)&y + sizeof(struct s); p++) printf("%d", *p); printf("\n"); } ---------------------------------------------------------------------- $ gcc -std=c11 -pedantic -Wall -Wextra test.c && ./a.out 11111111 $ gcc -std=c11 -pedantic -Wall -Wextra -O3 test.c && ./a.out 12221111 ---------------------------------------------------------------------- gcc x86-64 version: gcc (GCC) 10.0.1 20200320 (experimental) ----------------------------------------------------------------------
parent reply other threads:[~2020-03-20 11:23 UTC|newest] Thread overview: expand[flat|nested] mbox.gz Atom feed [parent not found: <bug-92486-4@http.gcc.gnu.org/bugzilla/>]
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-92486-4-uAbgeRZ9q3@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).