This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Structure initialisation problem PPC / g++-3.0.4
- From: Etienne Lorrain <etienne_lorrain at yahoo dot fr>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 4 Oct 2002 18:17:03 +0200 (CEST)
- Subject: Structure initialisation problem PPC / g++-3.0.4
Hello there,
I do not want to do a complete bug report because that can be my fault.
I compile:
----------------------------------------------------------------
class my_class
{
public:
my_class (void);
union my_union {
unsigned short all;
struct my_struct {
unsigned short a : 6;
unsigned short b : 1;
unsigned short c : 1;
unsigned short d : 1;
unsigned short e : 1;
unsigned short f : 1;
unsigned short g : 1;
unsigned short h : 1;
unsigned short i : 1;
unsigned short j : 1;
unsigned short k : 1;
} __attribute__ ((packed)) field;
};
void stwbrx (unsigned addr, unsigned data) {
asm volatile (" stwbrx %0,0,%1 \n"
: : "r" (data), "r" (addr)
);
}
void sthbrx (unsigned addr, unsigned short data) {
asm volatile (" sthbrx %0,0,%1 \n"
: : "r" (data), "r" (addr)
);
}
void fct (union my_union val) {
stwbrx (0xFFE0, 0x1122);
sthbrx (0xFFC0, val.all);
}
};
my_class::my_class (void) {
const my_class::my_union a_auto = { field: {
a: 0,
b: 0,
c: 0,
d: 0,
e: 0,
f: 0,
g: 0,
h: 0,
i: 1,
j: 0,
k: 0
} };
fct (a_auto);
static const my_class::my_union a_static = { field: {
a: 0,
b: 0,
c: 0,
d: 0,
e: 0,
f: 0,
g: 0,
h: 0,
i: 1,
j: 0,
k: 0
} };
fct (a_static);
}
----------------------------------------------------------------
Using the command:
../../local/bin/g++ -b powerpc-eabi -mcpu=603e -O2 -fno-strict-aliasing
-mmultiple -mstring -fno-rtti -S ../../src/bug.cpp
I get:
----------------------------------------------------------------
.file "bug.cpp"
.section .rodata
.align 1
.type _ZZN8my_classC1EvE8a_static,@object
.size _ZZN8my_classC1EvE8a_static,2
_ZZN8my_classC1EvE8a_static:
.byte 0x0
.byte 0x4 ######### LOOK HERE ###########
.section ".text"
.align 2
.globl _ZN8my_classC2Ev
.type _ZN8my_classC2Ev,@function
_ZN8my_classC2Ev:
stwu 1,-16(1)
li 0,0
sth 0,8(1)
li 9,0
lwz 0,8(1)
ori 9,9,65504
li 11,4386
oris 0,0,0x4
stw 0,8(1)
li 10,0 ######### LOOK HERE ###########
stwbrx 11,0,9
li 0,0
ori 0,0,65472
sthbrx 10,0,0 ######### LOOK HERE ###########
lis 9,_ZZN8my_classC1EvE8a_static@ha
li 11,0
lhz 10,_ZZN8my_classC1EvE8a_static@l(9) ######### LOOK HERE ###########
ori 11,11,65504
li 9,4386
stwbrx 9,0,11
li 0,0
ori 0,0,65472
sthbrx 10,0,0 ######### LOOK HERE ###########
addi 1,1,16
blr
.Lfe1:
.size _ZN8my_classC2Ev,.Lfe1-_ZN8my_classC2Ev
.align 2
.globl _ZN8my_classC1Ev
.type _ZN8my_classC1Ev,@function
_ZN8my_classC1Ev:
stwu 1,-16(1)
li 0,0
sth 0,8(1)
li 9,0
lwz 0,8(1)
ori 9,9,65504
li 11,4386
oris 0,0,0x4
stw 0,8(1)
li 10,0
stwbrx 11,0,9
li 0,0
ori 0,0,65472
sthbrx 10,0,0
lis 9,_ZZN8my_classC1EvE8a_static@ha
li 11,0
lhz 10,_ZZN8my_classC1EvE8a_static@l(9)
ori 11,11,65504
li 9,4386
stwbrx 9,0,11
li 0,0
ori 0,0,65472
sthbrx 10,0,0
addi 1,1,16
blr
.Lfe2:
.size _ZN8my_classC1Ev,.Lfe2-_ZN8my_classC1Ev
.ident "GCC: (GNU) 3.0.4"
----------------------------------------------------------------
This is (unfortunately) under cygwin, the cross compiler has been
compiled with this makefile fragment:
----------------------------------------------------------------
#FTPMIRROR := ftp://ftp.mirror.ac.uk/sites
GCC_VERSION := 3.0.4
#GCC_VERSION := 3.1.1
#GCC_VERSION := 3.2
#GCC_VERSION := 2.95.3
BINUTILS_VERSION := 2.12.1
#BINUTILS_VERSION := 2.13
#HOME = /home/Administrator # You can force it, but that is already in the
environment
PATH := $(HOME)/local/bin/:/usr/local/bin:/usr/bin:/bin
# The toolchain:
src/gcc-core-$(GCC_VERSION).tar.bz2:
wget --directory-prefix=src
$(FTPMIRROR)/sources.redhat.com/pub/gcc/releases/
gcc-$(GCC_VERSION)/gcc-core-$(GCC_VERSION).tar.bz2
src/binutils-$(BINUTILS_VERSION).tar.bz2:
wget --directory-prefix=src $(FTPMIRROR)/sources.redhat.com/pub/binutils/
releases/binutils-$(BINUTILS_VERSION).tar.bz2
src/gcc-g++-$(GCC_VERSION).tar.bz2:
wget --directory-prefix=src
$(FTPMIRROR)/sources.redhat.com/pub/gcc/releases/
gcc-$(GCC_VERSION)/gcc-g++-$(GCC_VERSION).tar.bz2
toolchain-src: src build src/gcc-core-$(GCC_VERSION).tar.bz2 src/gcc-g++-$(
GCC_VERSION).tar.bz2 src/binutils-$(BINUTILS_VERSION).tar.bz2
cd build && rm -rf toolchain
cd build && mkdir toolchain
cd build/toolchain && bunzip2.exe -c
../../src/binutils-$(BINUTILS_VERSION).
tar.bz2 | tar x
cd build/toolchain && bunzip2.exe -c ../../src/gcc-core-$(GCC_VERSION).tar.
bz2 | tar x
cd build/toolchain && bunzip2.exe -c ../../src/gcc-g++-$(GCC_VERSION).tar.
bz2 | tar x
cd build/toolchain && mv binutils-$(BINUTILS_VERSION) src
- cd build/toolchain && mv -u gcc-$(GCC_VERSION)/* src/
# You will get those messages:
# mv: cannot overwrite directory `src/config'
# mv: cannot overwrite directory `src/include'
# mv: cannot overwrite directory `src/libiberty'
cd build/toolchain && rm -rf gcc-$(GCC_VERSION)
native-toolchain: local
[ -d build/toolchain/src ] || $(MAKE) toolchain-src
cd build/toolchain && rm -rf native
cd build/toolchain && mkdir native
cd build/toolchain/native && ../src/configure --enable-version-specific-
runtime-libs --prefix=$(HOME)/local
cd build/toolchain/native && make bootstrap
# - cd build/toolchain/native && make -k check > check.log 2>&1
cd build/toolchain/native && make install
# PATH has to contains /home/Administrator/local/bin/ before anything else
here
# Add in /etc/profile the lines (after cd "$HOME") :
# export PATH=~/local/bin/:/usr/local/bin:/usr/bin:/bin
# export INFOPATH=~/local/info:/usr/local/info:/usr/info
# export MANPATH=~/local/man:/usr/local/man:/usr/man
# The following toolchain takes 3 hours to generate from scratch.
MPC603e-toolchain:
[ -x local/bin/gcc ] || $(MAKE) native-toolchain
cd build/toolchain && rm -rf MPC603e
cd build/toolchain && mkdir MPC603e
cd build/toolchain/MPC603e && ../src/configure --enable-version-specific-
runtime-libs --prefix=$(HOME)/local \
--program-prefix=x --target=powerpc-eabi --with-cpu=603e --enable-threads
--
disable-libgcj --enable-sjlj-exceptions
cd build/toolchain/MPC603e && make
cd build/toolchain/MPC603e && make install
# Cleanning after the toolchain generation:
clean-toolchain:
cd build && rm -rf toolchain
----------------------------------------------------------------
So the compiler says:
$ ../../local/bin/g++ -v
Reading specs from ../../local/bin/../lib/gcc-lib/i686-pc-cygwin/3.0.4/specs
Configured with:
Thread model: single
gcc version 3.0.4
----------------------------------------------------------------
When you see the source, "const my_class::my_union a_auto" is
exactly the same as "static const my_class::my_union a_static",
and _is_ _not_ _null_ because its field "i" is one.
The line:
li 10,0 ######### LOOK HERE ###########
loads the constant value zero to the register R10.
Should be something like:
li 10,0004
Thanks for any comment,
Etienne.
___________________________________________________________
Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français !
Yahoo! Mail : http://fr.mail.yahoo.com