From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11214 invoked by alias); 24 Jul 2009 05:22:30 -0000 Received: (qmail 11194 invoked by uid 48); 24 Jul 2009 05:22:17 -0000 Date: Fri, 24 Jul 2009 05:22:00 -0000 Subject: [Bug tree-optimization/40844] New: O2 optimizes out assignment to bitfield X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "jim at bodwin dot us" 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/msg01945.txt.bz2 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); } ============================ 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