* Function attributes and x32, x64 @ 2020-02-01 11:07 Edward Diener 2020-02-02 13:11 ` Liu Hao 2020-02-04 17:41 ` Jonathan Wakely 0 siblings, 2 replies; 9+ messages in thread From: Edward Diener @ 2020-02-01 11:07 UTC (permalink / raw) To: gcc-help Given the code: class cbase; int main() { typedef int __attribute__ ((__stdcall__)) (cbase::* atype)(); typedef int __attribute__ ((__cdecl__)) (cbase::* btype)(); typedef int __attribute__ ((__fastcall__)) (cbase::* ctype)(); typedef int __attribute__ ((__thiscall__)) (cbase::* dtype)(); return 0; } If I compile this for x64 (-m64) in gcc-9.2 I receive no errors or warnings. Yet https://gcc.gnu.org/onlinedocs/gcc/x86-Function-Attributes.html tells me that all four are only for x86-32 targets. Is the documentation wrong, is this a bug in gcc-9.2, or have I missed something ? ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Function attributes and x32, x64 2020-02-01 11:07 Function attributes and x32, x64 Edward Diener @ 2020-02-02 13:11 ` Liu Hao 2020-02-03 18:37 ` Edward Diener 2020-02-04 17:41 ` Jonathan Wakely 1 sibling, 1 reply; 9+ messages in thread From: Liu Hao @ 2020-02-02 13:11 UTC (permalink / raw) To: Edward Diener, gcc-help 在 2020/2/1 下午7:06, Edward Diener 写道: > Given the code: > > class cbase; > int main() > { > typedef int __attribute__ ((__stdcall__)) (cbase::* atype)(); > typedef int __attribute__ ((__cdecl__)) (cbase::* btype)(); > typedef int __attribute__ ((__fastcall__)) (cbase::* ctype)(); > typedef int __attribute__ ((__thiscall__)) (cbase::* dtype)(); > return 0; > } > > > If I compile this for x64 (-m64) in gcc-9.2 I receive no errors or > warnings. Yet > https://gcc.gnu.org/onlinedocs/gcc/x86-Function-Attributes.html tells me > that all four are only for x86-32 targets. Is the documentation wrong, > is this a bug in gcc-9.2, or have I missed something ? Are you compiling for Windows targets? If you target x64 Windows then it's likely that such attributes are accepted but ignored in line with MS compilers. -- Best regards, LH_Mouse ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Function attributes and x32, x64 2020-02-02 13:11 ` Liu Hao @ 2020-02-03 18:37 ` Edward Diener 2020-02-05 3:31 ` Liu Hao 0 siblings, 1 reply; 9+ messages in thread From: Edward Diener @ 2020-02-03 18:37 UTC (permalink / raw) To: gcc-help On 2/2/2020 8:11 AM, Liu Hao wrote: > å¨ 2020/2/1 ä¸å7:06, Edward Diener åé: >> Given the code: >> >> class cbase; >> int main() >>    { >>    typedef int __attribute__ ((__stdcall__)) (cbase::* atype)(); >>    typedef int __attribute__ ((__cdecl__)) (cbase::* btype)(); >>    typedef int __attribute__ ((__fastcall__)) (cbase::* ctype)(); >>    typedef int __attribute__ ((__thiscall__)) (cbase::* dtype)(); >>    return 0; >>    } >> >> >> If I compile this for x64 (-m64) in gcc-9.2 I receive no errors or >> warnings. Yet >> https://gcc.gnu.org/onlinedocs/gcc/x86-Function-Attributes.html tells me >> that all four are only for x86-32 targets. Is the documentation wrong, >> is this a bug in gcc-9.2, or have I missed something ? > > Are you compiling for Windows targets? If you target x64 Windows then > it's likely that such attributes are accepted but ignored in line with > MS compilers. On Windows in a 64-bit compile the attributes are ignored. On Linux in a 64-bit compile the attributes are ignored but at least there are indeed warning messages saying so. But the do9c should explain this. In both Windows and Linux in a 32-bit compile I get messages such as: test_calling_conventions.cpp: In function 'int main()': test_calling_conventions.cpp:5:62: error: stdcall and cdecl attributes are not compatible 5 | typedef int __attribute__ ((__cdecl__)) (cbase::* btype)(); | ^ test_calling_conventions.cpp:6:65: error: fastcall and cdecl attributes are not compatible 6 | typedef int __attribute__ ((__fastcall__)) (cbase::* ctype)(); | ^ test_calling_conventions.cpp:6:65: error: fastcall and stdcall attributes are not compatible test_calling_conventions.cpp:7:65: error: stdcall and thiscall attributes are not compatible 7 | typedef int __attribute__ ((__thiscall__)) (cbase::* dtype)(); | ^ test_calling_conventions.cpp:7:65: error: fastcall and thiscall attributes are not compatible test_calling_conventions.cpp:7:65: error: cdecl and thiscall attributes are not compatible This does not make sense to me as the compiler seems to be objecting to just having different pointer to member function types with different calling conventions for the same class, as if all member functions for a class must have the same calling conventions. Does gcc not allow different calling conventions for different member functions of a class, and, if so, where is this documented ? ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Function attributes and x32, x64 2020-02-03 18:37 ` Edward Diener @ 2020-02-05 3:31 ` Liu Hao 2020-02-05 9:52 ` Jonathan Wakely 0 siblings, 1 reply; 9+ messages in thread From: Liu Hao @ 2020-02-05 3:31 UTC (permalink / raw) To: Edward Diener, gcc-help [-- Attachment #1.1: Type: text/plain, Size: 1808 bytes --] 在 2020/2/4 上午2:37, Edward Diener 写道: > On 2/2/2020 8:11 AM, Liu Hao wrote: >> 在 2020/2/1 下午7:06, Edward Diener 写道: >>> Given the code: >>> >>> class cbase; >>> int main() >>> { >>> typedef int __attribute__ ((__stdcall__)) (cbase::* atype)(); >>> typedef int __attribute__ ((__cdecl__)) (cbase::* btype)(); >>> typedef int __attribute__ ((__fastcall__)) (cbase::* ctype)(); >>> typedef int __attribute__ ((__thiscall__)) (cbase::* dtype)(); >>> return 0; >>> } >>> > This does not make sense to me as the compiler seems to be objecting to > just having different pointer to member function types with different > calling conventions for the same class, as if all member functions for a > class must have the same calling conventions. Does gcc not allow > different calling conventions for different member functions of a class, > and, if so, where is this documented ? > > If I substitute the first typedef with an equivalent(?) using-declaration then I get a warning: ``` test.cc: In function ‘int main()’: test.cc:5:65: warning: ‘__stdcall__’ attribute only applies to function types [-Wattributes] using atype = int __attribute__ ((__stdcall__)) (cbase::* )(); ``` It looks to me that in the typedef case, the stdcall attribute attaches to the `int`, not the (indirect) function type. So long as GCC parses it as such, this eliminates the warning: ``` typedef int ( __attribute__ ((__stdcall__ )) cbase::* atype)(); // ^_______parenthesis_moved_______/ ``` The mangled names of these two types (which can be examined using `typeid(___).name`) don't differ, so I presume it is kind of a bug in intermediate representation. -- Best regards, LH_Mouse [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Function attributes and x32, x64 2020-02-05 3:31 ` Liu Hao @ 2020-02-05 9:52 ` Jonathan Wakely 2020-02-06 2:03 ` Liu Hao 0 siblings, 1 reply; 9+ messages in thread From: Jonathan Wakely @ 2020-02-05 9:52 UTC (permalink / raw) To: Liu Hao; +Cc: Edward Diener, gcc-help On Wed, 5 Feb 2020 at 03:31, Liu Hao <lh_mouse@126.com> wrote: > > 在 2020/2/4 上午2:37, Edward Diener 写道: > > On 2/2/2020 8:11 AM, Liu Hao wrote: > >> 在 2020/2/1 下午7:06, Edward Diener 写道: > >>> Given the code: > >>> > >>> class cbase; > >>> int main() > >>> { > >>> typedef int __attribute__ ((__stdcall__)) (cbase::* atype)(); > >>> typedef int __attribute__ ((__cdecl__)) (cbase::* btype)(); > >>> typedef int __attribute__ ((__fastcall__)) (cbase::* ctype)(); > >>> typedef int __attribute__ ((__thiscall__)) (cbase::* dtype)(); > >>> return 0; > >>> } > >>> > > > This does not make sense to me as the compiler seems to be objecting to > > just having different pointer to member function types with different > > calling conventions for the same class, as if all member functions for a > > class must have the same calling conventions. Does gcc not allow > > different calling conventions for different member functions of a class, > > and, if so, where is this documented ? > > > > > > If I substitute the first typedef with an equivalent(?) > using-declaration then I get a warning: > > ``` > test.cc: In function ‘int main()’: > test.cc:5:65: warning: ‘__stdcall__’ attribute only applies to function > types [-Wattributes] > using atype = int __attribute__ ((__stdcall__)) (cbase::* )(); > ``` > > It looks to me that in the typedef case, the stdcall attribute attaches > to the `int`, not the (indirect) function type. I think that's correct. The attribute grammar is confusing, but it does apply to the return type as used above, and that's obviously meaningless since 'int' has no calling convention. > So long as GCC parses it > as such, this eliminates the warning: > > ``` > typedef int ( __attribute__ ((__stdcall__ )) cbase::* atype)(); > // ^_______parenthesis_moved_______/ > ``` > > The mangled names of these two types (which can be examined using > `typeid(___).name`) don't differ, so I presume it is kind of a bug in > intermediate representation. > > > -- > Best regards, > LH_Mouse > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Function attributes and x32, x64 2020-02-05 9:52 ` Jonathan Wakely @ 2020-02-06 2:03 ` Liu Hao 0 siblings, 0 replies; 9+ messages in thread From: Liu Hao @ 2020-02-06 2:03 UTC (permalink / raw) To: Jonathan Wakely; +Cc: Edward Diener, gcc-help 在 2020/2/5 下午5:52, Jonathan Wakely 写道: > > I think that's correct. The attribute grammar is confusing, but it > does apply to the return type as used above, and that's obviously > meaningless since 'int' has no calling convention. > But this error only occurs when declaring a pointer-to-member-function using the `typedef` declaration, not a using-declaration: ```c++ class Z; int main() { extern int __attribute__((__stdcall__)) A(void); __attribute__((__stdcall__)) extern int A(void); extern int A(void) __attribute__((__stdcall__)); // ok typedef int __attribute__((__stdcall__)) (*B)(void); typedef __attribute__((__stdcall__)) int (*B)(void); typedef int (*B)(void) __attribute__((__stdcall__)); // ok typedef int __attribute__((__fastcall__)) (*C)(void); typedef __attribute__((__fastcall__)) int (*C)(void); typedef int (*C)(void) __attribute__((__fastcall__)); // ok typedef int __attribute__((__stdcall__)) (Z::*D)(void); typedef __attribute__((__stdcall__)) int (Z::*D)(void); typedef int (Z::*D)(void) __attribute__((__stdcall__)); // ok typedef int __attribute__((__fastcall__)) (Z::*E)(void); typedef __attribute__((__fastcall__)) int (Z::*E)(void); typedef int (Z::*E)(void) __attribute__((__fastcall__)); // error } ``` ``` lh_mouse@lhmouse-ideapad ~/Desktop $ i686-w64-mingw32-g++ test.c test.c: In function ‘int main()’: test.c:20:57: error: fastcall and stdcall attributes are not compatible typedef int __attribute__((__fastcall__)) (Z::*E)(void); ^ test.c:21:57: error: fastcall and stdcall attributes are not compatible typedef __attribute__((__fastcall__)) int (Z::*E)(void); ^ test.c:22:57: error: fastcall and stdcall attributes are not compatible typedef int (Z::*E)(void) __attribute__((__fastcall__)); ^ ``` -- Best regards, LH_Mouse ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Function attributes and x32, x64 2020-02-01 11:07 Function attributes and x32, x64 Edward Diener 2020-02-02 13:11 ` Liu Hao @ 2020-02-04 17:41 ` Jonathan Wakely 2020-02-04 23:24 ` Edward Diener 1 sibling, 1 reply; 9+ messages in thread From: Jonathan Wakely @ 2020-02-04 17:41 UTC (permalink / raw) To: Edward Diener; +Cc: gcc-help On Sat, 1 Feb 2020 at 11:07, Edward Diener <eldlistmailingz@tropicsoft.com> wrote: > > Given the code: > > class cbase; > int main() > { > typedef int __attribute__ ((__stdcall__)) (cbase::* atype)(); > typedef int __attribute__ ((__cdecl__)) (cbase::* btype)(); > typedef int __attribute__ ((__fastcall__)) (cbase::* ctype)(); > typedef int __attribute__ ((__thiscall__)) (cbase::* dtype)(); > return 0; > } > > > If I compile this for x64 (-m64) in gcc-9.2 I receive no errors or Aside: Please don't misuse the term "x32" (which means something different here), and avoid the dumb "x64" term (which is a Windows-ism). ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Function attributes and x32, x64 2020-02-04 17:41 ` Jonathan Wakely @ 2020-02-04 23:24 ` Edward Diener 2020-02-05 9:50 ` Jonathan Wakely 0 siblings, 1 reply; 9+ messages in thread From: Edward Diener @ 2020-02-04 23:24 UTC (permalink / raw) To: gcc-help On 2/4/2020 12:41 PM, Jonathan Wakely wrote: > On Sat, 1 Feb 2020 at 11:07, Edward Diener > <eldlistmailingz@tropicsoft.com> wrote: >> >> Given the code: >> >> class cbase; >> int main() >> { >> typedef int __attribute__ ((__stdcall__)) (cbase::* atype)(); >> typedef int __attribute__ ((__cdecl__)) (cbase::* btype)(); >> typedef int __attribute__ ((__fastcall__)) (cbase::* ctype)(); >> typedef int __attribute__ ((__thiscall__)) (cbase::* dtype)(); >> return 0; >> } >> >> >> If I compile this for x64 (-m64) in gcc-9.2 I receive no errors or > > Aside: Please don't misuse the term "x32" (which means something > different here), and avoid the dumb "x64" term (which is a > Windows-ism). > Do you prefer I should rather say x86-32 and x86-64 for 32-bit and 64-bit compilation respectively ? That is OK with me. But the issue of the error messages when using x86-32 compilation is still baffling to me. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Function attributes and x32, x64 2020-02-04 23:24 ` Edward Diener @ 2020-02-05 9:50 ` Jonathan Wakely 0 siblings, 0 replies; 9+ messages in thread From: Jonathan Wakely @ 2020-02-05 9:50 UTC (permalink / raw) To: Edward Diener; +Cc: gcc-help On Tue, 4 Feb 2020, 23:25 Edward Diener, <eldlistmailingz@tropicsoft.com> wrote: > > On 2/4/2020 12:41 PM, Jonathan Wakely wrote: > > On Sat, 1 Feb 2020 at 11:07, Edward Diener > > <eldlistmailingz@tropicsoft.com> wrote: > >> > >> Given the code: > >> > >> class cbase; > >> int main() > >> { > >> typedef int __attribute__ ((__stdcall__)) (cbase::* atype)(); > >> typedef int __attribute__ ((__cdecl__)) (cbase::* btype)(); > >> typedef int __attribute__ ((__fastcall__)) (cbase::* ctype)(); > >> typedef int __attribute__ ((__thiscall__)) (cbase::* dtype)(); > >> return 0; > >> } > >> > >> > >> If I compile this for x64 (-m64) in gcc-9.2 I receive no errors or > > > > Aside: Please don't misuse the term "x32" (which means something > > different here), and avoid the dumb "x64" term (which is a > > Windows-ism). > > > > Do you prefer I should rather say x86-32 Any of x86, ia32, or x86-32 is clear and unambiguous. x32 is a completely different thing. It's an alternative ABI for x86_64, using the x86_64 instruction set. x86 has been well understood for many, many years. Why people feel the need to call it x32 is beyond me. > and x86-64 Yes, or x86_64. Some people still use amd64 which is well understood, although Intel don't like it :-) "x64" is just silly. ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2020-02-06 2:03 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-02-01 11:07 Function attributes and x32, x64 Edward Diener 2020-02-02 13:11 ` Liu Hao 2020-02-03 18:37 ` Edward Diener 2020-02-05 3:31 ` Liu Hao 2020-02-05 9:52 ` Jonathan Wakely 2020-02-06 2:03 ` Liu Hao 2020-02-04 17:41 ` Jonathan Wakely 2020-02-04 23:24 ` Edward Diener 2020-02-05 9:50 ` Jonathan Wakely
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).