]> granicus.if.org Git - clang/commitdiff
[mingw] Don't mangle thiscall like fastcall etc
authorReid Kleckner <rnk@google.com>
Fri, 21 Dec 2018 01:40:29 +0000 (01:40 +0000)
committerReid Kleckner <rnk@google.com>
Fri, 21 Dec 2018 01:40:29 +0000 (01:40 +0000)
GCC does not mangle it when it is not explicit in the source.  The
mangler as currently written cannot differentiate between explicit and
implicit calling conventions, so we can't match GCC. Explicit thiscall
conventions are rare, so mangle as if the convention was implicit to be
as ABI compatible as possible.

Also fixes some tests using %itanium_abi_triple in some configurations
as a side effect.

Fixes PR40107.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349872 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ItaniumMangle.cpp
test/CodeGenCXX/mangle-win-ccs.cpp

index 8231ebe88bcd2d65304bd4a1515da9493334fc3e..98c843db31d62a1ce592e04d691fa661c51e40d3 100644 (file)
@@ -2662,12 +2662,18 @@ StringRef CXXNameMangler::getCallingConvQualifierName(CallingConv CC) {
     // FIXME: we should be mangling all of the above.
     return "";
 
+  case CC_X86ThisCall:
+    // FIXME: To match mingw GCC, thiscall should only be mangled in when it is
+    // used explicitly. At this point, we don't have that much information in
+    // the AST, since clang tends to bake the convention into the canonical
+    // function type. thiscall only rarely used explicitly, so don't mangle it
+    // for now.
+    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:
index 5336d1d7269b1112fa574814860b4b166f7bfba6..f5ddf974cf8f11e8d6bf072cecddfd52d91fed20 100644 (file)
@@ -17,7 +17,6 @@ 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)
@@ -28,16 +27,26 @@ int as_thiscall() { return func_as_ptr(f_thiscall); }
 // 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)
+// PR40107: We should mangle thiscall here but we don't because we can't
+// disambiguate it from the member pointer case below where it shouldn't be
+// mangled.
+//int as_thiscall() { return func_as_ptr(f_thiscall); }
+// CHECKX: define dso_local i32 @_Z11as_thiscallv()
+// CHECKX:   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); };
+
+// PR40107: In this case, the member function pointer uses the thiscall
+// convention, but GCC doesn't mangle it, so we don't either.
+// CHECK: define dso_local void @_Z15memptr_thiscallP3FooMS_FvvE(%struct.Foo* {{.*}})
+void memptr_thiscall(Foo *o, void (Foo::*mp)()) { (o->*mp)(); }
+
+// CHECK: define dso_local void @_Z12memptrCCTypeR3FooMS_U8fastcallFviiE(%struct.Foo* {{.*}}, { i32, i32 }* byval{{.*}})
 void memptrCCType(Foo &o, void (__attribute__((fastcall)) Foo::*mp)(int, int)) {
   (o.*mp)(1, 2);
 }