public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: Franz Sirl <Franz.Sirl-kernel@lauterbach.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, Subject: Re: optimization/7232: Incorrect code generate for volatiles Date: Tue, 09 Jul 2002 01:46:00 -0000 [thread overview] Message-ID: <20020709084602.6897.qmail@sources.redhat.com> (raw) The following reply was made to PR optimization/7232; it has been noted by GNATS. From: Franz Sirl <Franz.Sirl-kernel@lauterbach.com> To: svlu@enea.se Cc: gcc-gnats@gcc.gnu.org,karm@enea.se,steby@enea.se Subject: Re: optimization/7232: Incorrect code generate for volatiles Date: Tue, 09 Jul 2002 10:45:13 +0200 At 23:29 08.07.2002, Sven Lundblad wrote: >Hi, > >Thanks for the fast response! The generated code is still incorrect. Note the >two lwz instructtions that loads from the same address (r11+8). Please see my >comments below (and please correct me if I'm wrong). > >Regards, >Sven Lundblad > > .file "test.c" > .section ".text" > .align 2 > .type force_gcc_ppc_bug,@function > force_gcc_ppc_bug: > lis 11,ll@ha /* load address of ll into r11 high */ > li 0,4660 > la 11,ll@l(11) /* load address of ll into r11 low */ > lwz 10,8(11) /* load ll.rtFreeList into r10, should be > ll.rtFreeList->next (the lnk variable) > ??? */ > lwz 9,8(11) /* load ll.rtFreeList into r9 */ > stw 0,0(10) /* store 0x1234 into ll.rtFreeList->dummy WRONG! */ > mr 3,10 /* put ll.rtFreeList into r3 (but should be > the lnk > pointer) */ > lwz 0,4(9) /* load ll.rtFreeList->next into r0 */ > li 9,0 > stw 0,8(11) /* store ll.rtFreeList->next into ll.rtFreeList */ > li 0,18 > stw 9,4(10) > stb 0,42(10) /* store 0x12 into space outside allocated data! */ > blr > .Lfe1: > .size force_gcc_ppc_bug,.Lfe1-force_gcc_ppc_bug > .comm ll,12,4 > .ident "GCC: (GNU) 3.1.1 20020704 (prerelease)" Ah, now I understand your complaint, but this is not a compiler bug. If you look at your code static a_link *force_gcc_ppc_bug(void) { FreeList *freeNode; a_link *lnk; /* pop one node */ freeNode = ll.rtFreeList; ll.rtFreeList = ll.rtFreeList->next; freeNode->next = 0; lnk = (a_link *) freeNode; lnk->a = 0x1234; lnk->l = 0x12; return lnk; } and check against the aliasing rules in the C standard, you'll notice that you violate these rules thus invoking undefined behaviour. According to the C standard, the compiler can assume that lnk and FreeNode point to 2 _distinct_ objects and optimizes accordingly. Either fixup your code or use -fno-strict-aliasing to turn off this optimization at the price of slower code. I'll close the bug report. Franz.
next reply other threads:[~2002-07-09 8:46 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2002-07-09 1:46 Franz Sirl [this message] -- strict thread matches above, loose matches on Subject: below -- 2002-07-08 14:26 Sven Lundblad
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=20020709084602.6897.qmail@sources.redhat.com \ --to=franz.sirl-kernel@lauterbach.com \ --cc=gcc-prs@gcc.gnu.org \ --cc=nobody@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).