Problems with g++ and __attribute__((regparm(3)))
Rimantas Plaipa
Rimantas.Plaipa@gf.vu.lt
Tue Dec 12 03:06:00 GMT 2000
Documentation of gcc doesn't specify where function attributes have to
placed in declarations. All examples in the official docs have them after
the name of function, but the placement before the name works too. Such a
form is essential for compatibility with other compilers for Windows,
because it allows to use headers for them by defining
-D__stdcall=__attribute__((__stdcall__))
and so on.
But when the other popular attribute - __fastcall - is used in such a way a
disaster happens.
===== test.cpp ======
void* a(void* p, int i);
void* __attribute__((regparm(3))) b(void* p, int i);
void* b(void* p, int i){
return a(p,i);
}
======================
Compilation with g++ 2.95.2
g++ -O -fomit-frame-pointer -S test.cpp
gives:
_b__FPvi:
subl $12,%esp
call _a__FPvi
addl $12,%esp
ret
Function a(void*,int) (no attributes) is called as __fastcall !
If the attribute is placed after the name :
void* b(void* p, int i) __attribute__((regparm(3)));
or before the type of function:
__attribute__((regparm(3))) void* b(void* p, int i);
everything is OK:
_b__FPvi:
subl $12,%esp
addl $-8,%esp
pushl %edx
pushl %eax
call _a__FPvi
addl $16,%esp
addl $12,%esp
ret
g++ snapshot 20001104 have this bug too.
Rimantas Plaipa,
Department of Biochemistry and Biophysics,
Vilnius University,
Ciurlionio 21/27, Vilnius 2009, Lithuania.
E-mail: rp010gf@voruta.vu.lt
Phone: (370-2)-650381
Fax: (370-2)-236660
More information about the Gcc-bugs
mailing list