<div dir="ltr"><div dir="ltr">I sent <a href="https://reviews.llvm.org/D55781">https://reviews.llvm.org/D55781</a> and cc'd the original reviewers so we can decide if it's worth the cost.</div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Dec 14, 2018 at 5:17 PM Richard Smith <<a href="mailto:richard@metafoo.co.uk">richard@metafoo.co.uk</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto">Should this change be disableable by -fclang-abi-compat=7 or below?</div><br><div class="gmail_quote"><div dir="ltr">On Fri, 14 Dec 2018, 15:46 Reid Kleckner via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Author: rnk<br>
Date: Fri Dec 14 15:42:59 2018<br>
New Revision: 349212<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=349212&view=rev" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=349212&view=rev</a><br>
Log:<br>
Mangle calling conventions into function pointer types where GCC does<br>
<br>
Summary:<br>
GCC 5.1 began mangling these Windows calling conventions into function<br>
types, since they can be used for overloading. They've always been<br>
mangled in the MS ABI, but they are new to the Itanium mangler. Note<br>
that the calling convention doesn't appear as part of the main<br>
declaration, it only appears on function parameter types and other<br>
types.<br>
<br>
Fixes PR39860<br>
<br>
Reviewers: rjmccall, efriedma<br>
<br>
Subscribers: cfe-commits<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D55672" rel="noreferrer noreferrer" target="_blank">https://reviews.llvm.org/D55672</a><br>
<br>
Added:<br>
cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp<br>
cfe/trunk/test/CodeGenCXX/mangle-win64-ccs.cpp<br>
Modified:<br>
cfe/trunk/lib/AST/ItaniumMangle.cpp<br>
<br>
Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumMangle.cpp?rev=349212&r1=349211&r2=349212&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumMangle.cpp?rev=349212&r1=349211&r2=349212&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/ItaniumMangle.cpp (original)<br>
+++ cfe/trunk/lib/AST/ItaniumMangle.cpp Fri Dec 14 15:42:59 2018<br>
@@ -2648,13 +2648,8 @@ StringRef CXXNameMangler::getCallingConv<br>
case CC_C:<br>
return "";<br>
<br>
- case CC_X86StdCall:<br>
- case CC_X86FastCall:<br>
- case CC_X86ThisCall:<br>
case CC_X86VectorCall:<br>
case CC_X86Pascal:<br>
- case CC_Win64:<br>
- case CC_X86_64SysV:<br>
case CC_X86RegCall:<br>
case CC_AAPCS:<br>
case CC_AAPCS_VFP:<br>
@@ -2667,6 +2662,16 @@ StringRef CXXNameMangler::getCallingConv<br>
// FIXME: we should be mangling all of the above.<br>
return "";<br>
<br>
+ case CC_X86StdCall:<br>
+ return "stdcall";<br>
+ case CC_X86FastCall:<br>
+ return "fastcall";<br>
+ case CC_X86ThisCall:<br>
+ return "thiscall";<br>
+ case CC_X86_64SysV:<br>
+ return "sysv_abi";<br>
+ case CC_Win64:<br>
+ return "ms_abi";<br>
case CC_Swift:<br>
return "swiftcall";<br>
}<br>
<br>
Added: cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp?rev=349212&view=auto" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp?rev=349212&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp (added)<br>
+++ cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp Fri Dec 14 15:42:59 2018<br>
@@ -0,0 +1,61 @@<br>
+// RUN: %clang_cc1 %s -emit-llvm -triple i686-windows-gnu -o - | FileCheck %s<br>
+// RUN: %clang_cc1 %s -emit-llvm -triple i686-windows-itanium -o - | FileCheck %s<br>
+<br>
+// GCC 5.1 began mangling these Windows calling conventions into function<br>
+// types, since they can be used for overloading. They've always been mangled<br>
+// in the MS ABI, but they are new to the Itanium mangler. Note that the main<br>
+// function definition does not use a calling convention. Only function types<br>
+// that appear later use it.<br>
+<br>
+template <typename Fn> static int func_as_ptr(Fn fn) { return int(fn); }<br>
+<br>
+void f_cdecl(int, int);<br>
+void __attribute__((stdcall)) f_stdcall(int, int);<br>
+void __attribute__((fastcall)) f_fastcall(int, int);<br>
+void __attribute__((thiscall)) f_thiscall(int, int);<br>
+<br>
+int as_cdecl() { return func_as_ptr(f_cdecl); }<br>
+int as_stdcall() { return func_as_ptr(f_stdcall); }<br>
+int as_fastcall() { return func_as_ptr(f_fastcall); }<br>
+int as_thiscall() { return func_as_ptr(f_thiscall); }<br>
+<br>
+// CHECK: define dso_local i32 @_Z8as_cdeclv()<br>
+// CHECK: call i32 @_ZL11func_as_ptrIPFviiEEiT_(void (i32, i32)* @_Z7f_cdeclii)<br>
+<br>
+// CHECK: define dso_local i32 @_Z10as_stdcallv()<br>
+// CHECK: call i32 @_ZL11func_as_ptrIPU7stdcallFviiEEiT_(void (i32, i32)* @"\01__Z9f_stdcallii@8")<br>
+<br>
+// CHECK: define dso_local i32 @_Z11as_fastcallv()<br>
+// CHECK: call i32 @_ZL11func_as_ptrIPU8fastcallFviiEEiT_(void (i32, i32)* @"\01@_Z10f_fastcallii@8")<br>
+<br>
+// CHECK: define dso_local i32 @_Z11as_thiscallv()<br>
+// CHECK: call i32 @_ZL11func_as_ptrIPU8thiscallFviiEEiT_(void (i32, i32)* @_Z10f_thiscallii)<br>
+<br>
+// CHECK: define dso_local void @_Z11funcRefTypeRU8fastcallFviiE(void (i32, i32)* %fr)<br>
+void funcRefType(void(__attribute__((fastcall)) & fr)(int, int)) {<br>
+ fr(1, 2);<br>
+}<br>
+<br>
+// CHECK: define dso_local void @_Z12memptrCCTypeR3FooMS_U8fastcallFviiE(%struct.Foo* {{.*}}, { i32, i32 }* byval{{.*}})<br>
+struct Foo { void bar(int, int); };<br>
+void memptrCCType(Foo &o, void (__attribute__((fastcall)) Foo::*mp)(int, int)) {<br>
+ (o.*mp)(1, 2);<br>
+}<br>
+<br>
+// CHECK: define dso_local i32 @_Z17useTemplateFnTypev()<br>
+// CHECK: call i32 @_ZL14templateFnTypeIU8fastcallFviiEElPT_(void (i32, i32)* @"\01@_Z10f_fastcallii@8")<br>
+template <typename Fn> static long templateFnType(Fn *fn) { return long(fn); }<br>
+long useTemplateFnType() { return templateFnType(f_fastcall); }<br>
+<br>
+// CHECK: define weak_odr dso_local x86_fastcallcc void @"\01@_Z10fnTemplateIsEvv@0"()<br>
+// CHECK: define dso_local x86_fastcallcc void @"\01@_Z10fnTemplateIiEvv@0"()<br>
+template <typename T> void __attribute__((fastcall)) fnTemplate() {}<br>
+template void __attribute__((fastcall)) fnTemplate<short>();<br>
+template <> void __attribute__((fastcall)) fnTemplate<int>() {}<br>
+<br>
+// CHECK: define weak_odr dso_local x86_fastcallcc void (i32, i32)* @"\01@_Z12fnTempReturnIsEPU8fastcallFviiEv@0"()<br>
+// CHECK: define dso_local x86_fastcallcc void (i32, i32)* @"\01@_Z12fnTempReturnIiEPU8fastcallFviiEv@0"()<br>
+typedef void (__attribute__((fastcall)) *fp_cc_t)(int, int);<br>
+template <typename T> fp_cc_t __attribute__((fastcall)) fnTempReturn() { return nullptr; }<br>
+template fp_cc_t __attribute__((fastcall)) fnTempReturn<short>();<br>
+template <> fp_cc_t __attribute__((fastcall)) fnTempReturn<int>() { return nullptr; }<br>
<br>
Added: cfe/trunk/test/CodeGenCXX/mangle-win64-ccs.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-win64-ccs.cpp?rev=349212&view=auto" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-win64-ccs.cpp?rev=349212&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGenCXX/mangle-win64-ccs.cpp (added)<br>
+++ cfe/trunk/test/CodeGenCXX/mangle-win64-ccs.cpp Fri Dec 14 15:42:59 2018<br>
@@ -0,0 +1,26 @@<br>
+// RUN: %clang_cc1 -triple x86_64-windows-gnu -o - -emit-llvm %s | FileCheck %s -check-prefix CHECK-WIN<br>
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -o - -emit-llvm %s | FileCheck %s -check-prefix CHECK-LIN<br>
+<br>
+typedef __PTRDIFF_TYPE__ ptrdiff_t;<br>
+template <typename FTy> ptrdiff_t func_as_int(FTy *fp) { return ptrdiff_t(fp); }<br>
+<br>
+int f_plain(int);<br>
+int __attribute__((sysv_abi)) f_sysvabi(int);<br>
+int __attribute__((ms_abi)) f_msabi(int);<br>
+ptrdiff_t useThem() {<br>
+ ptrdiff_t rv = 0;<br>
+ rv += func_as_int(f_plain);<br>
+ rv += func_as_int(f_sysvabi);<br>
+ rv += func_as_int(f_msabi);<br>
+ return rv;<br>
+}<br>
+<br>
+// CHECK-WIN: define dso_local i64 @_Z7useThemv()<br>
+// CHECK-WIN: call i64 @_Z11func_as_intIFiiEExPT_(i32 (i32)* @_Z7f_plaini)<br>
+// CHECK-WIN: call i64 @_Z11func_as_intIU8sysv_abiFiiEExPT_(i32 (i32)* @_Z9f_sysvabii)<br>
+// CHECK-WIN: call i64 @_Z11func_as_intIFiiEExPT_(i32 (i32)* @_Z7f_msabii)<br>
+<br>
+// CHECK-LIN: define i64 @_Z7useThemv()<br>
+// CHECK-LIN: call i64 @_Z11func_as_intIFiiEElPT_(i32 (i32)* @_Z7f_plaini)<br>
+// CHECK-LIN: call i64 @_Z11func_as_intIFiiEElPT_(i32 (i32)* @_Z9f_sysvabii)<br>
+// CHECK-LIN: call i64 @_Z11func_as_intIU6ms_abiFiiEElPT_(i32 (i32)* @_Z7f_msabii)<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" rel="noreferrer" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div>
</blockquote></div>