G++ bug?
Toshiyasu Morita
tm@netcom.com
Mon Aug 3 14:45:00 GMT 1998
Compiler: egcs-1998-07-27
Host: i386-linux
Target: i386-linux
G++ seems to generate very bizarre and incorrect code for this code sample:
class MyClass;
typedef char (MyClass::*MyClassFuncPtr)( void );
typedef char (*AnyFuncPtr)( MyClass* );
class MyClass
{
public:
char A( void ) { return 'a'; }
char B( void ) { return 'b'; }
};
void main()
{
MyClass Instance;
MyClassFuncPtr FuncPtr1 = &MyClass::A;
(Instance.*FuncPtr1)();
}
When compiled as "gcc -O2 -S test.cpp" it generates a *huge* amount of
code for some reason, and uses %edx without initializing it:
gcc2_compiled.:
.text
.align 4
.globl main
.type main,@function
main:
.LFB1:
pushl %ebp
.LCFI0:
movl %esp,%ebp
.LCFI1:
subl $20,%esp
.LCFI2:
xorw %dx,%dx <- %edx used here without initialization
orl $-65536,%edx <-
pushl %edi
.LCFI3:
movl $A__7MyClass,%eax
pushl %esi
.LCFI4:
movl %eax,%ecx
pushl %ebx
.LCFI5:
movl %edx,%ebx
sarl $16,%ebx
testl %ebx,%ebx
jle .L6
movswl %cx,%eax
leal -1(%ebp),%esi
movl (%eax,%esi),%eax
movl %esi,-16(%ebp)
movl -8(%eax,%ebx,8),%esi
movl -4(%eax,%ebx,8),%edi
movl %esi,-12(%ebp)
movl %edi,-8(%ebp)
movl -8(%ebp),%edi
movl %edi,-20(%ebp)
jmp .L7
.align 4
.L6:
movl %eax,-20(%ebp)
leal -1(%ebp),%esi
movl %esi,-16(%ebp)
.L7:
movswl %dx,%edx
testl %ebx,%ebx
jle .L8
movswl -12(%ebp),%eax
addl %edx,%eax
jmp .L9
.align 4
.L8:
movl %edx,%eax
.L9:
addl -16(%ebp),%eax
pushl %eax
movl -20(%ebp),%edi
.LCFI6:
call *%edi
leal -32(%ebp),%esp
xorl %eax,%eax
popl %ebx
popl %esi
popl %edi
movl %ebp,%esp
popl %ebp
ret
Anyone know why this is happening and/or can offer a patch?
Also, sizeof(MyClassFuncPtr) is inexplicably eight bytes?
Toshi
More information about the Gcc-bugs
mailing list