This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/15872] New: h8300-hms-g++ generates wrong machine code when initializing static members of class templates
- From: "gcc-bugzilla at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 8 Jun 2004 10:55:48 -0000
- Subject: [Bug target/15872] New: h8300-hms-g++ generates wrong machine code when initializing static members of class templates
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
The error is, that the c++ compiler of gcc 3.4.0 generates wrong machine code when initializing
static members of class templates.
To demonstrate the error a test programm ( test.cc ) is translated to machine code
for two targets (avr and h8300-hms).
This test program defines a class template 'Foo' with a static integer variable 'foovar' which
is initialized with '35'.
---------------------- test.cc ----------------------
1: template<class T>
2: struct Foo {
3: static int foovar;
4: };
5:
6: template<class T>
7: int Foo<T>::foovar=35;
8:
9: int main(){
10: return Foo<int>::foovar;
11: }
-----------------------------------------------------
Test Programm compiled with 'avr-g++ -S -o h8-test.s test.cc' :
-------------------- avr-test.s ---------------------
1: .file "test.cc"
2: .arch avr2
3: __SREG__ = 0x3f
4: __SP_H__ = 0x3e
5: __SP_L__ = 0x3d
6: __tmp_reg__ = 0
7: __zero_reg__ = 1
8: .global __do_copy_data
9: .global __do_clear_bss
10: .text
11: .global main
12: .type main, @function
13: main:
14: /* prologue: frame size=0 */
15: ldi r28,lo8(__stack - 0)
16: ldi r29,hi8(__stack - 0)
17: out __SP_H__,r29
18: out __SP_L__,r28
19: /* prologue end (size=4) */
20: lds r24,_ZN3FooIiE6foovarE
21: lds r25,(_ZN3FooIiE6foovarE)+1
22: /* epilogue: frame size=0 */
23: rjmp exit
24: /* epilogue end (size=1) */
25: /* function int main() size 9 (4) */
26: .size main, .-main
27: .weak _ZN3FooIiE6foovarE
28: .data
29: .type _ZN3FooIiE6foovarE, @object
30: .size _ZN3FooIiE6foovarE, 2
31: _ZN3FooIiE6foovarE:
32: .word 35
33: /* File "test.cc": code 9 = 0x0009 ( 4), prologues 4, epilogues 1 */
-----------------------------------------------------
In avr assembler output a label/address '_ZN3FooIiE6foovarE' for the correspondending symbol
is created in the .data section.
Test Programm compiled with 'h8300-hms-g++ -S -o h8-test.s test.cc' :
-------------------- h8-test.s ---------------------
1: .file "test.cc"
2: .section .text
3: .align 1
4: .global _main
5: _main:
6: mov.w r6,@-r7
7: mov.w r7,r6
8: mov.w @__ZN3FooIiE6foovarE,r2
9: mov.w r2,r0
10: mov.w @r7+,r6
11: rts
12: .end
13: .ident "GCC: (GNU) 3.4.0"
-----------------------------------------------------
In h8300-hms assembler output the __ZN3FooIiE6foovarE is not defined and there doesn't exist an address in the
.data section.
The error does not occur when the static member variable (here: 'foovar') is not initialized. Then the compiler
correctly creates a .comm symbol.
Environment:
System: Linux faui00a 2.4.25 #2 SMP Wed Feb 18 19:58:48 CET 2004 i686 unknown
Architecture: i686
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: h8300-hitachi-hms
configured with: /tmp/gcc-dir/gcc-3.4.0/configure --enable-version-specific-runtime-libs --prefix=/proj/i4ciao/tools/gcc --enable-languages=c,c++ --target=h8300-hms
How-To-Repeat:
Compile a class template with a static member variable.
--
Summary: h8300-hms-g++ generates wrong machine code when
initializing static members of class templates
Product: gcc
Version: 3.4
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: georg dot blaschke at stud dot informatik dot uni-
erlangen dot de
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: h8300-hitachi-hms
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15872