public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/15872] New: h8300-hms-g++ generates wrong machine code when initializing static members of class templates
@ 2004-06-08 10:55 gcc-bugzilla at gcc dot gnu dot org
2004-06-08 11:51 ` [Bug target/15872] h8300-hms does not support implicit instantiations of templates pinskia at gcc dot gnu dot org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: gcc-bugzilla at gcc dot gnu dot org @ 2004-06-08 10:55 UTC (permalink / raw)
To: gcc-bugs
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug target/15872] h8300-hms does not support implicit instantiations of templates
2004-06-08 10:55 [Bug target/15872] New: h8300-hms-g++ generates wrong machine code when initializing static members of class templates gcc-bugzilla at gcc dot gnu dot org
@ 2004-06-08 11:51 ` pinskia at gcc dot gnu dot org
2004-06-08 16:29 ` georg dot blaschke at stud dot informatik dot uni-erlangen dot de
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-06-08 11:51 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-06-08 11:51 -------
Confirmed. Note you might want to explicant instantiation the template instead anyways as most
embeded targets are not going to support weak symbols at all.
--
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
Status|UNCONFIRMED |NEW
Ever Confirmed| |1
Keywords| |non-weak, wrong-code
Last reconfirmed|0000-00-00 00:00:00 |2004-06-08 11:51:51
date| |
Summary|h8300-hms-g++ generates |h8300-hms does not support
|wrong machine code when |implicit instantiations of
|initializing static members |templates
|of class templates |
Version|3.4 |3.4.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15872
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug target/15872] h8300-hms does not support implicit instantiations of templates
2004-06-08 10:55 [Bug target/15872] New: h8300-hms-g++ generates wrong machine code when initializing static members of class templates gcc-bugzilla at gcc dot gnu dot org
2004-06-08 11:51 ` [Bug target/15872] h8300-hms does not support implicit instantiations of templates pinskia at gcc dot gnu dot org
@ 2004-06-08 16:29 ` georg dot blaschke at stud dot informatik dot uni-erlangen dot de
2004-06-08 17:51 ` [Bug target/15872] h8300-hms does not support implicit instantiations of template static variables pinskia at gcc dot gnu dot org
2004-06-09 11:53 ` [Bug target/15872] h8300-hms-g++ generates wrong machine code when initializing static members of class templates georg dot blaschke at stud dot informatik dot uni-erlangen dot de
3 siblings, 0 replies; 5+ messages in thread
From: georg dot blaschke at stud dot informatik dot uni-erlangen dot de @ 2004-06-08 16:29 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From georg dot blaschke at stud dot informatik dot uni-erlangen dot de 2004-06-08 16:29 -------
(In reply to comment #1)
> Confirmed. Note you might want to explicant instantiation the template
instead anyways as most
> embeded targets are not going to support weak symbols at all.
Hm, at least avr and h8300-hms linker are supporting weak symbols.
And the summary is wrong now. Maybe my example wasn't that good.
The error has nothing to do with implicit template instantiaton.
Implicit template instantiation only works for function templates and
means that a function template can be implicitly instatiated by the
parameters of the function.
E.g.
-------------------------------------------
template<class T>
void func(T t){
/*
do stuff
*/
}
..
int i=123
func(i); \\ <- implicit template instatiation with an iteger type
..
-------------------------------------------
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15872
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug target/15872] h8300-hms does not support implicit instantiations of template static variables
2004-06-08 10:55 [Bug target/15872] New: h8300-hms-g++ generates wrong machine code when initializing static members of class templates gcc-bugzilla at gcc dot gnu dot org
2004-06-08 11:51 ` [Bug target/15872] h8300-hms does not support implicit instantiations of templates pinskia at gcc dot gnu dot org
2004-06-08 16:29 ` georg dot blaschke at stud dot informatik dot uni-erlangen dot de
@ 2004-06-08 17:51 ` pinskia at gcc dot gnu dot org
2004-06-09 11:53 ` [Bug target/15872] h8300-hms-g++ generates wrong machine code when initializing static members of class templates georg dot blaschke at stud dot informatik dot uni-erlangen dot de
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-06-08 17:51 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-06-08 17:51 -------
Well the summarry was just not the full thing, it has to do with template static variables and nothing
else if you explicantly instantiation the template static variable it is fine.
--
What |Removed |Added
----------------------------------------------------------------------------
Summary|h8300-hms does not support |h8300-hms does not support
|implicit instantiations of |implicit instantiations of
|templates |template static variables
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15872
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug target/15872] h8300-hms-g++ generates wrong machine code when initializing static members of class templates
2004-06-08 10:55 [Bug target/15872] New: h8300-hms-g++ generates wrong machine code when initializing static members of class templates gcc-bugzilla at gcc dot gnu dot org
` (2 preceding siblings ...)
2004-06-08 17:51 ` [Bug target/15872] h8300-hms does not support implicit instantiations of template static variables pinskia at gcc dot gnu dot org
@ 2004-06-09 11:53 ` georg dot blaschke at stud dot informatik dot uni-erlangen dot de
3 siblings, 0 replies; 5+ messages in thread
From: georg dot blaschke at stud dot informatik dot uni-erlangen dot de @ 2004-06-09 11:53 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From georg dot blaschke at stud dot informatik dot uni-erlangen dot de 2004-06-09 11:53 -------
(In reply to comment #3)
> [...]
> if you explicantly instantiation the template static variable it is fine.
I still do not understand what you meant with 'explicantly _instantiation_',but
assume your idea was to write an explicit _assignment_ statement for the
variable into the code, right?
Well, that will not work. I do not know before compile time which instantiations
of the class template do exist. The class template _might_ be instantiated for
many different types.
As there's no real workaround I set the severity back to 'normal'.
--
What |Removed |Added
----------------------------------------------------------------------------
Severity|enhancement |normal
Summary|h8300-hms does not support |h8300-hms-g++ generates
|implicit instantiations of |wrong machine code when
|template static variables |initializing static members
| |of class templates
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15872
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2004-06-09 11:53 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-08 10:55 [Bug target/15872] New: h8300-hms-g++ generates wrong machine code when initializing static members of class templates gcc-bugzilla at gcc dot gnu dot org
2004-06-08 11:51 ` [Bug target/15872] h8300-hms does not support implicit instantiations of templates pinskia at gcc dot gnu dot org
2004-06-08 16:29 ` georg dot blaschke at stud dot informatik dot uni-erlangen dot de
2004-06-08 17:51 ` [Bug target/15872] h8300-hms does not support implicit instantiations of template static variables pinskia at gcc dot gnu dot org
2004-06-09 11:53 ` [Bug target/15872] h8300-hms-g++ generates wrong machine code when initializing static members of class templates georg dot blaschke at stud dot informatik dot uni-erlangen dot de
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).