rnk created this revision. rnk added reviewers: rjmccall, efriedma. 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 https://reviews.llvm.org/D55672 Files: clang/lib/AST/ItaniumMangle.cpp clang/test/CodeGenCXX/mangle-win-ccs.cpp Index: clang/test/CodeGenCXX/mangle-win-ccs.cpp =================================================================== --- /dev/null +++ clang/test/CodeGenCXX/mangle-win-ccs.cpp @@ -0,0 +1,34 @@ +// 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 <typename Fn> static __PTRDIFF_TYPE__ func_as_ptr(Fn fn) { + return __PTRDIFF_TYPE__(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); + +__PTRDIFF_TYPE__ as_cdecl() { return func_as_ptr(f_cdecl); } +__PTRDIFF_TYPE__ as_stdcall() { return func_as_ptr(f_stdcall); } +__PTRDIFF_TYPE__ as_fastcall() { return func_as_ptr(f_fastcall); } +__PTRDIFF_TYPE__ 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) Index: clang/lib/AST/ItaniumMangle.cpp =================================================================== --- clang/lib/AST/ItaniumMangle.cpp +++ clang/lib/AST/ItaniumMangle.cpp @@ -2648,12 +2648,8 @@ 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: @@ -2667,6 +2663,14 @@ // 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_Win64: + return "ms_abi"; case CC_Swift: return "swiftcall"; }
Index: clang/test/CodeGenCXX/mangle-win-ccs.cpp =================================================================== --- /dev/null +++ clang/test/CodeGenCXX/mangle-win-ccs.cpp @@ -0,0 +1,34 @@ +// 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 <typename Fn> static __PTRDIFF_TYPE__ func_as_ptr(Fn fn) { + return __PTRDIFF_TYPE__(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); + +__PTRDIFF_TYPE__ as_cdecl() { return func_as_ptr(f_cdecl); } +__PTRDIFF_TYPE__ as_stdcall() { return func_as_ptr(f_stdcall); } +__PTRDIFF_TYPE__ as_fastcall() { return func_as_ptr(f_fastcall); } +__PTRDIFF_TYPE__ 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) Index: clang/lib/AST/ItaniumMangle.cpp =================================================================== --- clang/lib/AST/ItaniumMangle.cpp +++ clang/lib/AST/ItaniumMangle.cpp @@ -2648,12 +2648,8 @@ 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: @@ -2667,6 +2663,14 @@ // 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_Win64: + return "ms_abi"; case CC_Swift: return "swiftcall"; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits