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]

name mangling bug?



I think there's a problem with the name mangling method (huh, how many
times have you heard that before?) which can stop valid code compiling
or linking, and can cause it to be linked wrongly.  It's (hopefully)
architecture independent etc.  Source:

#define Mo2 Moo

enum Fu {One = 1, Two = 13};

enum x1 {};
enum Z2x {Bar = 1};

struct Monk
{
  template <Fu, class> void Mo2 () {}
  template <Fu, Z2x> void Moo () {}
  virtual ~Monk ()
  {
    Moo<One, Bar> ();
    Mo2<Two, x1> ();
  }
};

void Goit () { Monk monk; }

Which gives me the attached assembler, which won't assemble.  The
problem is that both the template instantiations mangle to the same
string "Moo__H22Fu13Z2x1_4Monk_v".  As you can see, there's an ambiguity
as to where the value of the first template parameter stops - is it a Fu
of value 1, followed by a value of type length 3 name "Z2x" value 1, or
is it a Fu of value 13, followed by a type length 2 name "x1".

I've tried it with -fnew-abi - no difference.  Perhaps there ought to be
an underscore after the value of the Fu, although it's not just a
problem in the mangling direction - the demangler doesn't cope with this
at the moment?

--

	.file	"template-mangling.cpp"
	.version	"01.01"
gcc2_compiled.:
.text
	.align 4
.globl Goit__Fv
	.type	 Goit__Fv,@function
Goit__Fv:
	pushl %ebp
	movl %esp,%ebp
	subl $40,%esp
	addl $-12,%esp
	leal -32(%ebp),%eax
	pushl %eax
	call __4Monk
	addl $16,%esp
	addl $-8,%esp
	pushl $2
	leal -32(%ebp),%eax
	pushl %eax
	call _._4Monk
	addl $16,%esp
.L10:
	movl %ebp,%esp
	popl %ebp
	ret
.Lfe1:
	.size	 Goit__Fv,.Lfe1-Goit__Fv
.section	.gnu.linkonce.t.__4Monk,"ax",@progbits
	.align 4
	.weak	__4Monk
	.type	 __4Monk,@function
__4Monk:
	pushl %ebp
	movl %esp,%ebp
	movl 8(%ebp),%edx
	movl $__vt_4Monk,(%edx)
.L12:
	movl %edx,%eax
	jmp .L11
.L11:
	movl %ebp,%esp
	popl %ebp
	ret
.Lfe2:
	.size	 __4Monk,.Lfe2-__4Monk
.section	.gnu.linkonce.t._._4Monk,"ax",@progbits
	.align 4
	.weak	_._4Monk
	.type	 _._4Monk,@function
_._4Monk:
	pushl %ebp
	movl %esp,%ebp
	subl $16,%esp
	pushl %esi
	pushl %ebx
	movl 8(%ebp),%esi
	movl 12(%ebp),%ebx
	movl $__vt_4Monk,(%esi)
	addl $-12,%esp
	pushl %esi
	call Moo__H22Fu13Z2x1_4Monk_v
	addl $16,%esp
	addl $-12,%esp
	pushl %esi
	call Moo__H22Fu13Z2x1_4Monk_v
	addl $16,%esp
.L7:
	movl %ebx,%eax
	andl $1,%eax
	testl %eax,%eax
	je .L9
	addl $-12,%esp
	pushl %esi
	call __builtin_delete
	addl $16,%esp
	jmp .L9
	.p2align 4,,7
.L8:
.L9:
.L2:
	leal -24(%ebp),%esp
	popl %ebx
	popl %esi
	movl %ebp,%esp
	popl %ebp
	ret
.Lfe3:
	.size	 _._4Monk,.Lfe3-_._4Monk
	.weak	__vt_4Monk
.section	.gnu.linkonce.d.__vt_4Monk,"aw",@progbits
	.align 4
	.type	 __vt_4Monk,@object
	.size	 __vt_4Monk,16
__vt_4Monk:
	.long 0
	.long 0
	.long _._4Monk
	.zero	4
.section	.gnu.linkonce.t.Moo__H22Fu13Z2x1_4Monk_v,"ax",@progbits
	.align 4
	.weak	Moo__H22Fu13Z2x1_4Monk_v
	.type	 Moo__H22Fu13Z2x1_4Monk_v,@function
Moo__H22Fu13Z2x1_4Monk_v:
	pushl %ebp
	movl %esp,%ebp
	movl 8(%ebp),%eax
	jmp .L4
	jmp .L3
	.p2align 4,,7
.L4:
.L3:
	movl %ebp,%esp
	popl %ebp
	ret
.Lfe4:
	.size	 Moo__H22Fu13Z2x1_4Monk_v,.Lfe4-Moo__H22Fu13Z2x1_4Monk_v
	.align 4
	.weak	Moo__H22Fu13Z2x1_4Monk_v
	.type	 Moo__H22Fu13Z2x1_4Monk_v,@function
Moo__H22Fu13Z2x1_4Monk_v:
	pushl %ebp
	movl %esp,%ebp
	movl 8(%ebp),%eax
	jmp .L6
	jmp .L5
	.p2align 4,,7
.L6:
.L5:
	movl %ebp,%esp
	popl %ebp
	ret
.Lfe5:
	.size	 Moo__H22Fu13Z2x1_4Monk_v,.Lfe5-Moo__H22Fu13Z2x1_4Monk_v
	.ident	"GCC: (GNU) gcc-2.96 19990602 (experimental)"

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