Re: r349212 - Mangle calling conventions into function pointer types where GCC does
I sent https://reviews.llvm.org/D55781 and cc'd the original reviewers so we can decide if it's worth the cost. On Fri, Dec 14, 2018 at 5:17 PM Richard Smith wrote: > Should this change be disableable by -fclang-abi-compat=7 or below? > > On Fri, 14 Dec 2018, 15:46 Reid Kleckner via cfe-commits < > cfe-commits@lists.llvm.org wrote: > >> Author: rnk >> Date: Fri Dec 14 15:42:59 2018 >> New Revision: 349212 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=349212=rev >> Log: >> Mangle calling conventions into function pointer types where GCC does >> >> Summary: >> GCC 5.1 began mangling these Windows calling conventions into function >> types, since they can be used for overloading. They've always been >> mangled in the MS ABI, but they are new to the Itanium mangler. Note >> that the calling convention doesn't appear as part of the main >> declaration, it only appears on function parameter types and other >> types. >> >> Fixes PR39860 >> >> Reviewers: rjmccall, efriedma >> >> Subscribers: cfe-commits >> >> Differential Revision: https://reviews.llvm.org/D55672 >> >> Added: >> cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp >> cfe/trunk/test/CodeGenCXX/mangle-win64-ccs.cpp >> Modified: >> cfe/trunk/lib/AST/ItaniumMangle.cpp >> >> Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumMangle.cpp?rev=349212=349211=349212=diff >> >> == >> --- cfe/trunk/lib/AST/ItaniumMangle.cpp (original) >> +++ cfe/trunk/lib/AST/ItaniumMangle.cpp Fri Dec 14 15:42:59 2018 >> @@ -2648,13 +2648,8 @@ StringRef CXXNameMangler::getCallingConv >>case CC_C: >> return ""; >> >> - case CC_X86StdCall: >> - case CC_X86FastCall: >> - case CC_X86ThisCall: >>case CC_X86VectorCall: >>case CC_X86Pascal: >> - case CC_Win64: >> - case CC_X86_64SysV: >>case CC_X86RegCall: >>case CC_AAPCS: >>case CC_AAPCS_VFP: >> @@ -2667,6 +2662,16 @@ StringRef CXXNameMangler::getCallingConv >> // FIXME: we should be mangling all of the above. >> return ""; >> >> + case CC_X86StdCall: >> +return "stdcall"; >> + case CC_X86FastCall: >> +return "fastcall"; >> + case CC_X86ThisCall: >> +return "thiscall"; >> + case CC_X86_64SysV: >> +return "sysv_abi"; >> + case CC_Win64: >> +return "ms_abi"; >>case CC_Swift: >> return "swiftcall"; >>} >> >> Added: cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp?rev=349212=auto >> >> == >> --- cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp (added) >> +++ cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp Fri Dec 14 15:42:59 2018 >> @@ -0,0 +1,61 @@ >> +// RUN: %clang_cc1 %s -emit-llvm -triple i686-windows-gnu -o - | >> FileCheck %s >> +// RUN: %clang_cc1 %s -emit-llvm -triple i686-windows-itanium -o - | >> FileCheck %s >> + >> +// GCC 5.1 began mangling these Windows calling conventions into function >> +// types, since they can be used for overloading. They've always been >> mangled >> +// in the MS ABI, but they are new to the Itanium mangler. Note that the >> main >> +// function definition does not use a calling convention. Only function >> types >> +// that appear later use it. >> + >> +template static int func_as_ptr(Fn fn) { return int(fn); } >> + >> +void f_cdecl(int, int); >> +void __attribute__((stdcall)) f_stdcall(int, int); >> +void __attribute__((fastcall)) f_fastcall(int, int); >> +void __attribute__((thiscall)) f_thiscall(int, int); >> + >> +int as_cdecl() { return func_as_ptr(f_cdecl); } >> +int as_stdcall() { return func_as_ptr(f_stdcall); } >> +int as_fastcall() { return func_as_ptr(f_fastcall); } >> +int as_thiscall() { return func_as_ptr(f_thiscall); } >> + >> +// CHECK: define dso_local i32 @_Z8as_cdeclv() >> +// CHECK: call i32 @_ZL11func_as_ptrIPFviiEEiT_(void (i32, i32)* >> @_Z7f_cdeclii) >> + >> +// CHECK: define dso_local i32 @_Z10as_stdcallv() >> +// CHECK: call i32 @_ZL11func_as_ptrIPU7stdcallFviiEEiT_(void (i32, >> i32)* @"\01__Z9f_stdcallii@8") >> + >> +// CHECK: define dso_local i32 @_Z11as_fastcallv() >> +// CHECK: call i32 @_ZL11func_as_ptrIPU8fastcallFviiEEiT_(void (i32, >> i32)* @"\01@_Z10f_fastcallii@8") >> + >> +// CHECK: define dso_local i32 @_Z11as_thiscallv() >> +// CHECK: call i32 @_ZL11func_as_ptrIPU8thiscallFviiEEiT_(void (i32, >> i32)* @_Z10f_thiscallii) >> + >> +// CHECK: define dso_local void @_Z11funcRefTypeRU8fastcallFviiE(void >> (i32, i32)* %fr) >> +void funcRefType(void(__attribute__((fastcall)) & fr)(int, int)) { >> + fr(1, 2); >> +} >> + >> +// CHECK: define dso_local void >> @_Z12memptrCCTypeR3FooMS_U8fastcallFviiE(%struct.Foo* {{.*}}, { i32, i32 }* >> byval{{.*}}) >> +struct Foo { void bar(int, int); }; >> +void memptrCCType(Foo , void (__attribute__((fastcall)) Foo::*mp)(int, >>
Re: r349212 - Mangle calling conventions into function pointer types where GCC does
Should this change be disableable by -fclang-abi-compat=7 or below? On Fri, 14 Dec 2018, 15:46 Reid Kleckner via cfe-commits < cfe-commits@lists.llvm.org wrote: > Author: rnk > Date: Fri Dec 14 15:42:59 2018 > New Revision: 349212 > > URL: http://llvm.org/viewvc/llvm-project?rev=349212=rev > Log: > Mangle calling conventions into function pointer types where GCC does > > Summary: > GCC 5.1 began mangling these Windows calling conventions into function > types, since they can be used for overloading. They've always been > mangled in the MS ABI, but they are new to the Itanium mangler. Note > that the calling convention doesn't appear as part of the main > declaration, it only appears on function parameter types and other > types. > > Fixes PR39860 > > Reviewers: rjmccall, efriedma > > Subscribers: cfe-commits > > Differential Revision: https://reviews.llvm.org/D55672 > > Added: > cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp > cfe/trunk/test/CodeGenCXX/mangle-win64-ccs.cpp > Modified: > cfe/trunk/lib/AST/ItaniumMangle.cpp > > Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumMangle.cpp?rev=349212=349211=349212=diff > > == > --- cfe/trunk/lib/AST/ItaniumMangle.cpp (original) > +++ cfe/trunk/lib/AST/ItaniumMangle.cpp Fri Dec 14 15:42:59 2018 > @@ -2648,13 +2648,8 @@ StringRef CXXNameMangler::getCallingConv >case CC_C: > return ""; > > - case CC_X86StdCall: > - case CC_X86FastCall: > - case CC_X86ThisCall: >case CC_X86VectorCall: >case CC_X86Pascal: > - case CC_Win64: > - case CC_X86_64SysV: >case CC_X86RegCall: >case CC_AAPCS: >case CC_AAPCS_VFP: > @@ -2667,6 +2662,16 @@ StringRef CXXNameMangler::getCallingConv > // FIXME: we should be mangling all of the above. > return ""; > > + case CC_X86StdCall: > +return "stdcall"; > + case CC_X86FastCall: > +return "fastcall"; > + case CC_X86ThisCall: > +return "thiscall"; > + case CC_X86_64SysV: > +return "sysv_abi"; > + case CC_Win64: > +return "ms_abi"; >case CC_Swift: > return "swiftcall"; >} > > Added: cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp?rev=349212=auto > > == > --- cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp (added) > +++ cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp Fri Dec 14 15:42:59 2018 > @@ -0,0 +1,61 @@ > +// RUN: %clang_cc1 %s -emit-llvm -triple i686-windows-gnu -o - | > FileCheck %s > +// RUN: %clang_cc1 %s -emit-llvm -triple i686-windows-itanium -o - | > FileCheck %s > + > +// GCC 5.1 began mangling these Windows calling conventions into function > +// types, since they can be used for overloading. They've always been > mangled > +// in the MS ABI, but they are new to the Itanium mangler. Note that the > main > +// function definition does not use a calling convention. Only function > types > +// that appear later use it. > + > +template static int func_as_ptr(Fn fn) { return int(fn); } > + > +void f_cdecl(int, int); > +void __attribute__((stdcall)) f_stdcall(int, int); > +void __attribute__((fastcall)) f_fastcall(int, int); > +void __attribute__((thiscall)) f_thiscall(int, int); > + > +int as_cdecl() { return func_as_ptr(f_cdecl); } > +int as_stdcall() { return func_as_ptr(f_stdcall); } > +int as_fastcall() { return func_as_ptr(f_fastcall); } > +int as_thiscall() { return func_as_ptr(f_thiscall); } > + > +// CHECK: define dso_local i32 @_Z8as_cdeclv() > +// CHECK: call i32 @_ZL11func_as_ptrIPFviiEEiT_(void (i32, i32)* > @_Z7f_cdeclii) > + > +// CHECK: define dso_local i32 @_Z10as_stdcallv() > +// CHECK: call i32 @_ZL11func_as_ptrIPU7stdcallFviiEEiT_(void (i32, > i32)* @"\01__Z9f_stdcallii@8") > + > +// CHECK: define dso_local i32 @_Z11as_fastcallv() > +// CHECK: call i32 @_ZL11func_as_ptrIPU8fastcallFviiEEiT_(void (i32, > i32)* @"\01@_Z10f_fastcallii@8") > + > +// CHECK: define dso_local i32 @_Z11as_thiscallv() > +// CHECK: call i32 @_ZL11func_as_ptrIPU8thiscallFviiEEiT_(void (i32, > i32)* @_Z10f_thiscallii) > + > +// CHECK: define dso_local void @_Z11funcRefTypeRU8fastcallFviiE(void > (i32, i32)* %fr) > +void funcRefType(void(__attribute__((fastcall)) & fr)(int, int)) { > + fr(1, 2); > +} > + > +// CHECK: define dso_local void > @_Z12memptrCCTypeR3FooMS_U8fastcallFviiE(%struct.Foo* {{.*}}, { i32, i32 }* > byval{{.*}}) > +struct Foo { void bar(int, int); }; > +void memptrCCType(Foo , void (__attribute__((fastcall)) Foo::*mp)(int, > int)) { > + (o.*mp)(1, 2); > +} > + > +// CHECK: define dso_local i32 @_Z17useTemplateFnTypev() > +// CHECK: call i32 @_ZL14templateFnTypeIU8fastcallFviiEElPT_(void (i32, > i32)* @"\01@_Z10f_fastcallii@8") > +template static long templateFnType(Fn *fn) { return > long(fn); } > +long useTemplateFnType() {
r349212 - Mangle calling conventions into function pointer types where GCC does
Author: rnk Date: Fri Dec 14 15:42:59 2018 New Revision: 349212 URL: http://llvm.org/viewvc/llvm-project?rev=349212=rev Log: Mangle calling conventions into function pointer types where GCC does Summary: GCC 5.1 began mangling these Windows calling conventions into function types, since they can be used for overloading. They've always been mangled in the MS ABI, but they are new to the Itanium mangler. Note that the calling convention doesn't appear as part of the main declaration, it only appears on function parameter types and other types. Fixes PR39860 Reviewers: rjmccall, efriedma Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D55672 Added: cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp cfe/trunk/test/CodeGenCXX/mangle-win64-ccs.cpp Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumMangle.cpp?rev=349212=349211=349212=diff == --- cfe/trunk/lib/AST/ItaniumMangle.cpp (original) +++ cfe/trunk/lib/AST/ItaniumMangle.cpp Fri Dec 14 15:42:59 2018 @@ -2648,13 +2648,8 @@ StringRef CXXNameMangler::getCallingConv case CC_C: return ""; - case CC_X86StdCall: - case CC_X86FastCall: - case CC_X86ThisCall: case CC_X86VectorCall: case CC_X86Pascal: - case CC_Win64: - case CC_X86_64SysV: case CC_X86RegCall: case CC_AAPCS: case CC_AAPCS_VFP: @@ -2667,6 +2662,16 @@ StringRef CXXNameMangler::getCallingConv // FIXME: we should be mangling all of the above. return ""; + case CC_X86StdCall: +return "stdcall"; + case CC_X86FastCall: +return "fastcall"; + case CC_X86ThisCall: +return "thiscall"; + case CC_X86_64SysV: +return "sysv_abi"; + case CC_Win64: +return "ms_abi"; case CC_Swift: return "swiftcall"; } Added: cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp?rev=349212=auto == --- cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp (added) +++ cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp Fri Dec 14 15:42:59 2018 @@ -0,0 +1,61 @@ +// RUN: %clang_cc1 %s -emit-llvm -triple i686-windows-gnu -o - | FileCheck %s +// RUN: %clang_cc1 %s -emit-llvm -triple i686-windows-itanium -o - | FileCheck %s + +// GCC 5.1 began mangling these Windows calling conventions into function +// types, since they can be used for overloading. They've always been mangled +// in the MS ABI, but they are new to the Itanium mangler. Note that the main +// function definition does not use a calling convention. Only function types +// that appear later use it. + +template static int func_as_ptr(Fn fn) { return int(fn); } + +void f_cdecl(int, int); +void __attribute__((stdcall)) f_stdcall(int, int); +void __attribute__((fastcall)) f_fastcall(int, int); +void __attribute__((thiscall)) f_thiscall(int, int); + +int as_cdecl() { return func_as_ptr(f_cdecl); } +int as_stdcall() { return func_as_ptr(f_stdcall); } +int as_fastcall() { return func_as_ptr(f_fastcall); } +int as_thiscall() { return func_as_ptr(f_thiscall); } + +// CHECK: define dso_local i32 @_Z8as_cdeclv() +// CHECK: call i32 @_ZL11func_as_ptrIPFviiEEiT_(void (i32, i32)* @_Z7f_cdeclii) + +// CHECK: define dso_local i32 @_Z10as_stdcallv() +// CHECK: call i32 @_ZL11func_as_ptrIPU7stdcallFviiEEiT_(void (i32, i32)* @"\01__Z9f_stdcallii@8") + +// CHECK: define dso_local i32 @_Z11as_fastcallv() +// CHECK: call i32 @_ZL11func_as_ptrIPU8fastcallFviiEEiT_(void (i32, i32)* @"\01@_Z10f_fastcallii@8") + +// CHECK: define dso_local i32 @_Z11as_thiscallv() +// CHECK: call i32 @_ZL11func_as_ptrIPU8thiscallFviiEEiT_(void (i32, i32)* @_Z10f_thiscallii) + +// CHECK: define dso_local void @_Z11funcRefTypeRU8fastcallFviiE(void (i32, i32)* %fr) +void funcRefType(void(__attribute__((fastcall)) & fr)(int, int)) { + fr(1, 2); +} + +// CHECK: define dso_local void @_Z12memptrCCTypeR3FooMS_U8fastcallFviiE(%struct.Foo* {{.*}}, { i32, i32 }* byval{{.*}}) +struct Foo { void bar(int, int); }; +void memptrCCType(Foo , void (__attribute__((fastcall)) Foo::*mp)(int, int)) { + (o.*mp)(1, 2); +} + +// CHECK: define dso_local i32 @_Z17useTemplateFnTypev() +// CHECK: call i32 @_ZL14templateFnTypeIU8fastcallFviiEElPT_(void (i32, i32)* @"\01@_Z10f_fastcallii@8") +template static long templateFnType(Fn *fn) { return long(fn); } +long useTemplateFnType() { return templateFnType(f_fastcall); } + +// CHECK: define weak_odr dso_local x86_fastcallcc void @"\01@_Z10fnTemplateIsEvv@0"() +// CHECK: define dso_local x86_fastcallcc void @"\01@_Z10fnTemplateIiEvv@0"() +template void __attribute__((fastcall)) fnTemplate() {} +template void __attribute__((fastcall)) fnTemplate(); +template <> void __attribute__((fastcall)) fnTemplate() {} + +// CHECK: define weak_odr