This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Alignment error in struct init on powerpc



GCC-Version: 2.95.2
Host: Debian-2.1/i386
Target: powerpc-eabi

Bug description:
When initialising a structure of size 8 and alignment 2 from a const
struct, g++ uses the 'lfd/stfd' instructions for copying the contents of
the source structure to the destination structure. This results in an
alignment error if either the source- or destination structs are not
word-aligned.

The test-program:
---- alignmentbug.h ----
struct smallstruct
{
   char a1;
   char a2;
};
struct bigstruct
{
   char a1;
   char a2;
   char a3;
   char a4;
   char a5;
   char a6;
   short a7;
};

---- alignmentbug.cpp ----
#include "alignmentbug.h"

extern const smallstruct initsmall;
extern const bigstruct initbig;

smallstruct a = initsmall;
bigstruct b = initbig;

---- alignmentbug1.cpp ----
#include "alignmentbug.h"

extern const smallstruct initsmall = { 0, 0 };
extern const bigstruct initbig = { 0, 0, 0, 0, 0, 0, 0 };
extern const short dummy = 0;

---- compiler-run ----
powerpc-eabi-g++ -O alignmentbug.cpp alignmentbug1.cpp

---- listing of the generated a.out ----
a.out:     file format elf32-powerpc

Disassembly of section .text:

01800074 <__static_initialization_and_destruction_0>:
 1800074:       38 00 00 00     li      r0,0
 1800078:       60 00 ff ff     ori     r0,r0,65535
 180007c:       7c 04 00 00     cmpw    r4,r0
 1800080:       4c 82 00 20     bnelr   
 1800084:       2c 03 00 00     cmpwi   r3,0
 1800088:       4d 82 00 20     beqlr   
 180008c:       3d 60 01 84     lis     r11,388
 1800090:       3d 20 01 84     lis     r9,388
 1800094:       a0 09 01 24     lhz     r0,292(r9)
 1800098:       b0 0b 01 30     sth     r0,304(r11)
 180009c:       3d 60 01 84     lis     r11,388
 18000a0:       39 6b 01 32     addi    r11,r11,306
                                                ^^^
r11 is not word aligned!
 18000a4:       3d 20 01 84     lis     r9,388
 18000a8:       39 29 01 26     addi    r9,r9,294
                                              ^^^
r9 is not word aligned!
 18000ac:       c8 09 00 00     lfd     f0,0(r9)
floating point access to r9 not word aligned!
 18000b0:       d8 0b 00 00     stfd    f0,0(r11)
floating point access to r11 not word aligned!
 18000b4:       4e 80 00 20     blr

..
-- 
Dr. Johannes Reisinger
System Design
FREQUENTIS
A-1120 Wien, Spittelbreitengasse 34
http://www.frequentis.com
Tel: +43/1/81150-2329, Fax -2299
mailto:jreising@frequentis.com

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]