public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "jakub at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/23561] New: nonoverlapping_memrefs_p returns true even for overlapping memory references Date: Thu, 25 Aug 2005 15:39:00 -0000 [thread overview] Message-ID: <20050825153435.23561.jakub@gcc.gnu.org> (raw) struct A { char a1[1]; char a2[5]; char a3[1]; char a4[2048 - 7]; } a; typedef __SIZE_TYPE__ size_t; extern void *memset (void *, int, size_t); extern void *memcpy (void *, const void *, size_t); extern int memcmp (const void *, const void *, size_t); extern void abort (void); void bar (struct A *x) { size_t i; if (memcmp (x, "\1HELLO\1", sizeof "\1HELLO\1")) abort (); for (i = 0; i < sizeof (x->a4); i++) if (x->a4[i]) abort (); } int foo (void) { memset (&a, 0, sizeof (a)); a.a1[0] = 1; memcpy (a.a2, "HELLO", sizeof "HELLO"); a.a3[0] = 1; bar (&a); return 0; } int main (void) { foo (); return 0; } is miscompiled on ppc-linux at -O2 and -O3 (assuming the testcase is valid). The 2 memcpy (a.a2, ...) instructions get swapped with a.a3[0] = 1 insn during sched2, because nonoverlapping_memrefs_p says: (mem/s:HI (plus:SI (reg/f:SI 29 29 [120]) (const_int 5 [0x5])) [0 a.a2+4 S2 A8]) and (mem/s:QI (plus:SI (reg/f:SI 29 29 [120]) (const_int 6 [0x6])) [0 a.a3+0 S1 A8]) don't overlap (as they have recorded different fields of the same structure). The patch that introduced this optimization was: http://gcc.gnu.org/ml/gcc-patches/2001-12/msg00072.html Now, is that valid C to overflow from one field into another one within the same structure? If yes, I think nonoverlapping_memrefs_p would need to take into account offsets, sizes and relative distance of the fields. If not, then perhaps glibc -D_FORTIFY_SOURCE=2 should use __builtin_offset_size (dst, 1) rather than (dst, 0) even for memcpy/etc. -- Summary: nonoverlapping_memrefs_p returns true even for overlapping memory references Product: gcc Version: 4.0.2 Status: UNCONFIRMED Severity: critical Priority: P2 Component: rtl-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: jakub at gcc dot gnu dot org CC: gcc-bugs at gcc dot gnu dot org,rth at gcc dot gnu dot org GCC target triplet: ppc-linux http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23561
next reply other threads:[~2005-08-25 15:35 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2005-08-25 15:39 jakub at gcc dot gnu dot org [this message] 2005-08-25 15:48 ` [Bug rtl-optimization/23561] " pinskia at gcc dot gnu dot org 2005-08-25 15:53 ` jakub at gcc dot gnu dot org 2005-08-25 15:54 ` Andrew Pinski 2005-08-25 16:11 ` pinskia at physics dot uc dot edu 2005-08-25 16:36 ` rth at gcc dot gnu dot org 2005-08-25 16:42 ` rth at gcc dot gnu dot org 2005-08-25 17:23 ` mark at codesourcery dot com 2005-08-25 19:06 ` jakub at gcc dot gnu dot org 2005-08-26 22:03 ` cvs-commit at gcc dot gnu dot org 2005-08-27 12:04 ` cvs-commit at gcc dot gnu dot org 2005-09-02 8:49 ` jakub at gcc dot gnu dot org 2005-09-07 14:12 ` pinskia at gcc dot gnu dot org
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=20050825153435.23561.jakub@gcc.gnu.org \ --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).