Bug 49119 - PowerPC: Wrong code with designated initializers and bit fields
Summary: PowerPC: Wrong code with designated initializers and bit fields
Status: RESOLVED DUPLICATE of bug 49768
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.6.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-23 07:59 UTC by Sebastian Huber
Modified: 2011-08-24 10:34 UTC (History)
1 user (show)

See Also:
Host:
Target: powerpc-rtems4.11-gcc
Build:
Known to work: 4.4.5, 4.6.2
Known to fail: 4.6.1
Last reconfirmed:


Attachments
C source code corresponding to the assembler code. (23.98 KB, text/plain)
2011-05-23 08:00 UTC, Sebastian Huber
Details
Generated assembler file. (1.93 KB, text/plain)
2011-08-23 15:01 UTC, Sebastian Huber
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sebastian Huber 2011-05-23 07:59:29 UTC
With GCC 4.6.1 20110513 for PowerPC with -O2 I get this:

Disassembly of section .text:

00000000 <wrong_code>:
   0:   38 00 00 00     li      r0,0   <- This is wrong
   4:   7c 10 9b a6     mtspr   624,r0 <-
   8:   3d 20 00 00     lis     r9,0
   c:   80 09 00 04     lwz     r0,4(r9)
  10:   7c 11 9b a6     mtspr   625,r0
  14:   3d 20 00 00     lis     r9,0
  18:   80 09 00 08     lwz     r0,8(r9)
  1c:   7c 12 9b a6     mtspr   626,r0
  20:   3d 20 00 00     lis     r9,0
  24:   80 09 00 0c     lwz     r0,12(r9)
  28:   7c 13 9b a6     mtspr   627,r0
  2c:   7c 00 07 a4     tlbld   r0
  30:   4e 80 00 20     blr

00000034 <valid_code>:
  34:   3c 00 10 05     lis     r0,4101 <- This is valid
  38:   7c 10 9b a6     mtspr   624,r0  <-
  3c:   3d 20 00 00     lis     r9,0
  40:   80 09 00 1c     lwz     r0,28(r9)
  44:   7c 11 9b a6     mtspr   625,r0
  48:   3d 20 00 00     lis     r9,0
  4c:   80 09 00 20     lwz     r0,32(r9)
  50:   7c 12 9b a6     mtspr   626,r0
  54:   3d 20 00 00     lis     r9,0
  58:   80 09 00 24     lwz     r0,36(r9)
  5c:   7c 13 9b a6     mtspr   627,r0
  60:   7c 00 07 a4     tlbld   r0
  64:   4e 80 00 20     blr

Disassembly of section .rodata:

00000000 <mmu_setup_wrong>:
   0:   10 05 00 00
   4:   c0 00 01 00
   8:   3f ff 80 0a
   c:   3f ff 80 0f
        ...

00000018 <mmu_setup_valid>:
  18:   10 05 00 00
  1c:   c0 00 01 00
  20:   3f ff 80 0a
  24:   3f ff 80 0f

The designated initializer
  .MAS0 = { .B = { .TLBSEL = 1, .ESEL = 5 } },
leads to wrong code.  On the other hand
  .MAS0 = { .R = 0x10050000 },
leads to valid code.
Comment 1 Sebastian Huber 2011-05-23 08:00:49 UTC
Created attachment 24334 [details]
C source code corresponding to the assembler code.
Comment 2 Sebastian Huber 2011-08-22 12:19:24 UTC
This bug is not present in GCC 4.7.0 20110820.  Does anyone know which commit fixed this problem?  Is it possible to integrate the fix in GCC 4.6?
Comment 3 Mikael Pettersson 2011-08-22 16:40:35 UTC
I can't reproduce the wrong code on powerpc64-linux (with -m32), or on m68k-linux (also big-endian, assuming it's an endianess issue) with gcc-4.6.2-recentish.

How exactly was your gcc configured, and how did you invoke it on this test case?

Also please inspect the generated assembly code (gcc -S) rather than disassembled object code (objdump -d).  Disassembly tends to omit relocation data.
Comment 4 Sebastian Huber 2011-08-23 15:01:59 UTC
Created attachment 25084 [details]
Generated assembler file.

Command line:

powerpc-rtems4.11-gcc -O2 -save-temps -fverbose-asm -c bspstart.i -o bspstart.o

GCC configure options:

powerpc-rtems4.11-gcc --version --verbose
Using built-in specs.
COLLECT_GCC=powerpc-rtems4.11-gcc
COLLECT_LTO_WRAPPER=/opt/rtems-4.11/libexec/gcc/powerpc-rtems4.11/4.6.1/lto-wrapper
powerpc-rtems4.11-gcc (GCC) 4.6.1 20110513 (prerelease)
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


Target: powerpc-rtems4.11
Configured with: /home/sh/archive/gcc-4.6-20110513-work/configure --prefix=/opt/rtems-4.11 --target=powerpc-rtems4.11  --verbose --with-gnu-as --with-gnu-ld --with-newlib --disable-libstdcxx-pch --disable-nls --without-included-gettext --disable-win32-registry --enable-version-specific-runtime-libs --enable-threads --enable-newlib-io-c99-formats --enable-languages=c,c++
Thread model: rtems
gcc version 4.6.1 20110513 (prerelease) (GCC) 
COLLECT_GCC_OPTIONS='--version' '-v'
 /opt/rtems-4.11/libexec/gcc/powerpc-rtems4.11/4.6.1/cc1 -quiet -v -Dmpc750 help-dummy -quiet -dumpbase help-dummy -auxbase help-dummy -version --version -o /tmp/ccMl1sdZ.s
GNU C (GCC) version 4.6.1 20110513 (prerelease) (powerpc-rtems4.11)
        compiled by GNU C version 4.4.1 [gcc-4_4-branch revision 150839], GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
COLLECT_GCC_OPTIONS='--version' '-v'
 /opt/rtems-4.11/lib/gcc/powerpc-rtems4.11/4.6.1/../../../../powerpc-rtems4.11/bin/as -v -mppc -many --version -o /tmp/cckFLHZM.o /tmp/ccMl1sdZ.s
GNU assembler version 2.21.1 (powerpc-rtems4.11) using BFD version (GNU Binutils) 2.21.1
GNU assembler (GNU Binutils) 2.21.1
Copyright 2011 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or later.
This program has absolutely no warranty.
This assembler was configured for a target of `powerpc-rtems4.11'.
COMPILER_PATH=/opt/rtems-4.11/libexec/gcc/powerpc-rtems4.11/4.6.1/:/opt/rtems-4.11/libexec/gcc/powerpc-rtems4.11/4.6.1/:/opt/rtems-4.11/libexec/gcc/powerpc-rtems4.11/:/opt/rtems-4.11/lib/gcc/powerpc-rtems4.11/4.6.1/:/opt/rtems-4.11/lib/gcc/powerpc-rtems4.11/:/opt/rtems-4.11/lib/gcc/powerpc-rtems4.11/4.6.1/../../../../powerpc-rtems4.11/bin/
LIBRARY_PATH=/opt/rtems-4.11/lib/gcc/powerpc-rtems4.11/4.6.1/:/opt/rtems-4.11/lib/gcc/powerpc-rtems4.11/4.6.1/../../../../powerpc-rtems4.11/lib/
COLLECT_GCC_OPTIONS='--version' '-v'
 /opt/rtems-4.11/libexec/gcc/powerpc-rtems4.11/4.6.1/collect2 --eh-frame-hdr -V -dn -Bstatic --version /opt/rtems-4.11/lib/gcc/powerpc-rtems4.11/4.6.1/../../../../powerpc-rtems4.11/lib/crt0.o -L/opt/rtems-4.11/lib/gcc/powerpc-rtems4.11/4.6.1 -L/opt/rtems-4.11/lib/gcc/powerpc-rtems4.11/4.6.1/../../../../powerpc-rtems4.11/lib /tmp/cckFLHZM.o -lgcc -lc -lgcc
collect2 version 4.6.1 20110513 (prerelease) (PowerPC Embedded)
/opt/rtems-4.11/lib/gcc/powerpc-rtems4.11/4.6.1/../../../../powerpc-rtems4.11/bin/ld --eh-frame-hdr -V -dn -Bstatic --version /opt/rtems-4.11/lib/gcc/powerpc-rtems4.11/4.6.1/../../../../powerpc-rtems4.11/lib/crt0.o -L/opt/rtems-4.11/lib/gcc/powerpc-rtems4.11/4.6.1 -L/opt/rtems-4.11/lib/gcc/powerpc-rtems4.11/4.6.1/../../../../powerpc-rtems4.11/lib /tmp/cckFLHZM.o -lgcc -lc -lgcc
GNU ld (GNU Binutils) 2.21.1
  Supported emulations:
   elf32ppc
GNU ld (GNU Binutils) 2.21.1
Copyright 2011 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.
Comment 5 Sebastian Huber 2011-08-24 08:20:19 UTC
It seems that this problem is also fixed in GCC 4.6.2 20110819.
Comment 6 Mikael Pettersson 2011-08-24 10:25:39 UTC
For the record, this was fixed on 4.6 branch by r176438, the fix for PR49768.  The test cases are essentially the same, so PR49119 is a dupe of PR49768.
Comment 7 Sebastian Huber 2011-08-24 10:34:05 UTC
Thanks for the pointer.

*** This bug has been marked as a duplicate of bug 49768 ***