For a code:
//------------
void board_init_f (ulong bootflag)
{
  register volatile gd_t *gd asm ("r29");
  bd_t *bd;
  ulong len, addr, addr_sp;
  gd_t *id;
  init_fnc_t **init_fnc_ptr;

  gd=0xff55ff55;
  __asm__ __volatile__("or 29, 29, 29");
  memset ((void *) gd, 0, sizeof (gd_t));
  ........
//------------
the following assembly is generated:
//------------
fff88ec8 <board_init_f>:
fff88ec8:       94 21 ff d0     stwu    r1,-48(r1)
fff88ecc:       7c 08 02 a6     mflr    r0
fff88ed0:       be e1 00 0c     stmw    r23,12(r1)
fff88ed4:       90 01 00 34     stw     r0,52(r1)
fff88ed8:       42 9f 00 05     bcl-    20,4*cr7+so,fff88edc<board_init_f+0x14>
fff88edc:       7f c8 02 a6     mflr    r30
fff88ee0:       80 1e ff e8     lwz     r0,-24(r30)
fff88ee4:       7f c0 f2 14     add     r30,r0,r30
fff88ee8:       7c 7f 1b 78     mr      r31,r3
        /* problematic code here */
fff88eec:       7f bd eb 78     mr      r29,r29
fff88ef0:       3c 60 ff 55     lis     r3,-171
fff88ef4:       60 63 ff 55     ori     r3,r3,65365
fff88ef8:       38 80 00 00     li      r4,0
fff88efc:       38 a0 00 30     li      r5,48
fff88f00:       4b ff f9 19     bl      fff88818 <memset>
.....
//------------
It is seen from here, that r29 does not get initialized, despite "volatile" 
specifier for variable gd (gcc is called with "-ffixed-r29"). This bug is 
present in gcc-4.0.0 too.

For reference: code generated by gcc-3.4.4:
//------------
fff88cb8 <board_init_f>:
fff88cb8:       94 21 ff d8     stwu    r1,-40(r1)
fff88cbc:       7c 08 02 a6     mflr    r0
fff88cc0:       bf 01 00 08     stmw    r24,8(r1)
fff88cc4:       90 01 00 2c     stw     r0,44(r1)
fff88cc8:       42 9f 00 05     bcl-    20,4*cr7+so,fff88ccc<board_init_f+0x14>
fff88ccc:       7f c8 02 a6     mflr    r30
fff88cd0:       80 1e ff e8     lwz     r0,-24(r30)
fff88cd4:       7f c0 f2 14     add     r30,r0,r30
fff88cd8:       7c 78 1b 78     mr      r24,r3
           /* correct code */
fff88cdc:       3f a0 ff 55     lis     r29,-171
fff88ce0:       63 bd ff 55     ori     r29,r29,65365
fff88ce4:       7f bd eb 78     mr      r29,r29
fff88ce8:       7f a3 eb 78     mr      r3,r29
fff88cec:       38 80 00 00     li      r4,0
fff88cf0:       38 a0 00 30     li      r5,48
fff88cf4:       4b ff f8 ed     bl      fff885e0 <memset>
....
//--------------

-- 
           Summary: Volatile register access incorrectly optimized
           Product: gcc
           Version: 4.0.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: oakad at yahoo dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-cygwin
  GCC host triplet: i686-pc-cygwin
GCC target triplet: powerpc-eabi-gcc


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23444

Reply via email to