From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20972 invoked by alias); 24 Jul 2009 05:54:51 -0000 Received: (qmail 20935 invoked by alias); 24 Jul 2009 05:54:38 -0000 Date: Fri, 24 Jul 2009 05:54:00 -0000 Message-ID: <20090724055438.20934.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug tree-optimization/40844] O2 optimizes out assignment to bitfield In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "pinskia at gmail dot com" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2009-07/txt/msg01949.txt.bz2 ------- 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" 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 : > 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