public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "pinskia at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/40844] O2 optimizes out assignment to bitfield Date: Fri, 24 Jul 2009 05:54:00 -0000 [thread overview] Message-ID: <20090724055438.20934.qmail@sourceware.org> (raw) In-Reply-To: <bug-40844-17983@http.gcc.gnu.org/bugzilla/> ------- Comment #1 from pinskia at gmail dot com 2009-07-24 05:54 ------- Subject: Re: New: O2 optimizes out assignment to bitfield Sent from my iPhone On Jul 23, 2009, at 10:22 PM, "jim at bodwin dot us" <gcc-bugzilla@gcc.gnu.org > wrote: > Incorrect code is produced for the following source with the O2 > option. In > particular, the assignment to the bitfield field2 is optimized out > of the code > entirely and regImage is left all zero. Correct code is produced > with the O1 > option and (at least) with gcc version 4.3.2. > > ==================== Source Code > > typedef struct hwreg { > short field1 : 4; > short field2 : 2; > short field3 : 10; > } hwreg_t; > > void foo(volatile short *hwPtr, short f2) { > hwreg_t regImage; // Place to build reg image bit-by-bit > *(short *) ®Image = 0; > > regImage.field2 = f2; > > *hwPtr = *((short *) ®Image); > } I think you are violating c/c++ aliasing rules here. > > ============================ Object dump > > > /tmp/foo.o: file format elf32-littlearm > > > Disassembly of section .text: > > 00000000 <foo>: > 0: e3a03000 mov r3, #0 ; 0x0 > 4: e24dd004 sub sp, sp, #4 ; 0x4 > 8: e1c030b0 strh r3, [r0] > c: e28dd004 add sp, sp, #4 ; 0x4 > 10: e12fff1e bx lr > > ============================ gcc -v output > > Configured with: ../gcc-4.4.1/configure --target=arm-elf --disable- > __cxa_atexit > --with-newlib --enable-languages=c,c++ --with-gnu-as --with-gnu-ld > --with-gxx-include-dir=/home/jmb/arm-elf/include --prefix=/home/jmb/ > arm-elf : > (reconfigured) ../gcc-4.4.1/configure --target=arm-elf --disable- > __cxa_atexit > --with-newlib --enable-languages=c,c++ --with-gnu-as --with-gnu-ld > --with-gxx-include-dir=/home/jmb/arm-elf/include --prefix=/home/jmb/ > arm-elf > Thread model: single > gcc version 4.4.1 (GCC) > > > -- > Summary: O2 optimizes out assignment to bitfield > Product: gcc > Version: 4.4.1 > Status: UNCONFIRMED > Severity: critical > Priority: P3 > Component: tree-optimization > AssignedTo: unassigned at gcc dot gnu dot org > ReportedBy: jim at bodwin dot us > GCC build triplet: i486-pc-linux-gnu > GCC host triplet: i486-pc-linux-gnu > GCC target triplet: arm-elf > > > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40844 > -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40844
next prev parent reply other threads:[~2009-07-24 5:54 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2009-07-24 5:22 [Bug tree-optimization/40844] New: " jim at bodwin dot us 2009-07-24 5:54 ` pinskia at gmail dot com [this message] 2009-07-24 5:54 ` Andrew Pinski 2009-07-24 12:26 ` [Bug tree-optimization/40844] " rguenth 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=20090724055438.20934.qmail@sourceware.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).