r232254 - MS ABI: Mangle virtual member pointer thunks with the correct CC

David Majnemer david.majnemer at gmail.com
Fri Mar 13 23:34:41 PDT 2015


Author: majnemer
Date: Sat Mar 14 01:34:41 2015
New Revision: 232254

URL: http://llvm.org/viewvc/llvm-project?rev=232254&view=rev
Log:
MS ABI: Mangle virtual member pointer thunks with the correct CC

Virtual member pointers are implemented using a thunk.  We assumed that
the calling convention for this thunk was always __thiscall for 32-bit
targets and __cdecl for 64-bit targets.  However, this is not the case.
Mangle in whichever calling convention is appropriate for this member
function thunk.

Modified:
    cfe/trunk/lib/AST/MicrosoftMangle.cpp
    cfe/trunk/test/CodeGenCXX/microsoft-abi-virtual-member-pointers.cpp
    cfe/trunk/test/CodeGenCXX/microsoft-abi-vmemptr-conflicts.cpp

Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=232254&r1=232253&r2=232254&view=diff
==============================================================================
--- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
+++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Sat Mar 14 01:34:41 2015
@@ -583,7 +583,7 @@ void MicrosoftCXXNameMangler::mangleVirt
   Out << "$B";
   mangleNumber(OffsetInVFTable);
   Out << 'A';
-  Out << (PointersAre64Bit ? 'A' : 'E');
+  mangleCallingConvention(MD->getType()->getAs<FunctionProtoType>());
 }
 
 void MicrosoftCXXNameMangler::mangleName(const NamedDecl *ND) {

Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-virtual-member-pointers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-virtual-member-pointers.cpp?rev=232254&r1=232253&r2=232254&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/microsoft-abi-virtual-member-pointers.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/microsoft-abi-virtual-member-pointers.cpp Sat Mar 14 01:34:41 2015
@@ -18,6 +18,7 @@ struct C {
   virtual int bar(int, double);
   virtual S baz(int);
   virtual S qux(U);
+  virtual void thud(...);
 };
 
 namespace {
@@ -43,6 +44,9 @@ void f() {
   S (C::*ptr5)(U);
   ptr5 = &C::qux;
 
+  void (C::*ptr6)(...);
+  ptr6 = &C::thud;
+
 
 // CHECK32-LABEL: define void @"\01?f@@YAXXZ"()
 // CHECK32: store i8* bitcast (void (%struct.C*, ...)* @"\01??_9C@@$BA at AE" to i8*), i8** %ptr
@@ -146,6 +150,21 @@ void f() {
 // CHECK64: [[CALLEE:%.*]] = load void (%struct.C*, ...)*, void (%struct.C*, ...)** [[VPTR]]
 // CHECK64: musttail call void (%struct.C*, ...)* [[CALLEE]](%struct.C* %{{.*}}, ...)
 // CHECK64: ret void
+// CHECK64: }
+
+// Thunk for calling the fifth virtual function in C which uses the __cdecl calling convention.
+// CHECK32-LABEL: define linkonce_odr void @"\01??_9C@@$BBA at AA"(%struct.C* %this, ...) {{.*}} comdat align 2 {
+// CHECK32: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)*, void (%struct.C*, ...)** %{{.*}}, i64 4
+// CHECK32: [[CALLEE:%.*]] = load void (%struct.C*, ...)*, void (%struct.C*, ...)** [[VPTR]]
+// CHECK32: musttail call void (%struct.C*, ...)* [[CALLEE]](%struct.C* %{{.*}}, ...)
+// CHECK32: ret void
+// CHECK32: }
+//
+// CHECK64-LABEL: define linkonce_odr void @"\01??_9C@@$BCA at AA"(%struct.C* %this, ...) {{.*}} comdat align 2 {
+// CHECK64: [[VPTR:%.*]] = getelementptr inbounds void (%struct.C*, ...)*, void (%struct.C*, ...)** %{{.*}}, i64 4
+// CHECK64: [[CALLEE:%.*]] = load void (%struct.C*, ...)*, void (%struct.C*, ...)** [[VPTR]]
+// CHECK64: musttail call void (%struct.C*, ...)* [[CALLEE]](%struct.C* %{{.*}}, ...)
+// CHECK64: ret void
 // CHECK64: }
 
 // CHECK32: #[[ATTR]] = {{{.*}}"thunk"{{.*}}}

Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-vmemptr-conflicts.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-vmemptr-conflicts.cpp?rev=232254&r1=232253&r2=232254&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/microsoft-abi-vmemptr-conflicts.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/microsoft-abi-vmemptr-conflicts.cpp Sat Mar 14 01:34:41 2015
@@ -93,9 +93,9 @@ void f(C *c) {
 }
 
 // CHECK-LABEL: define void @"\01?f at cdecl_inalloca@@YAXPAUC at 1@@Z"(%"struct.cdecl_inalloca::C"* %c)
-// CHECK: call void bitcast (void (%"struct.cdecl_inalloca::C"*, ...)* @"\01??_9C at cdecl_inalloca@@$BA at AE" to void (%"struct.cdecl_inalloca::C"*)*)(%"struct.cdecl_inalloca::C"* %{{.*}})
-// CHECK: call void bitcast (void (%"struct.cdecl_inalloca::C"*, ...)* @"\01??_9C at cdecl_inalloca@@$BA at AE" to void (<{ %"struct.cdecl_inalloca::C"*, %"struct.cdecl_inalloca::Big" }>*)*)(<{ %"struct.cdecl_inalloca::C"*, %"struct.cdecl_inalloca::Big" }>* inalloca %{{.*}})
+// CHECK: call void bitcast (void (%"struct.cdecl_inalloca::C"*, ...)* @"\01??_9C at cdecl_inalloca@@$BA at AA" to void (%"struct.cdecl_inalloca::C"*)*)(%"struct.cdecl_inalloca::C"* %{{.*}})
+// CHECK: call void bitcast (void (%"struct.cdecl_inalloca::C"*, ...)* @"\01??_9C at cdecl_inalloca@@$BA at AA" to void (<{ %"struct.cdecl_inalloca::C"*, %"struct.cdecl_inalloca::Big" }>*)*)(<{ %"struct.cdecl_inalloca::C"*, %"struct.cdecl_inalloca::Big" }>* inalloca %{{.*}})
 
-// CHECK-LABEL: define linkonce_odr void @"\01??_9C at cdecl_inalloca@@$BA at AE"(%"struct.cdecl_inalloca::C"* %this, ...) {{.*}} comdat
+// CHECK-LABEL: define linkonce_odr void @"\01??_9C at cdecl_inalloca@@$BA at AA"(%"struct.cdecl_inalloca::C"* %this, ...) {{.*}} comdat
 // CHECK: musttail call void (%"struct.cdecl_inalloca::C"*, ...)* %{{.*}}(%"struct.cdecl_inalloca::C"* %{{.*}}, ...)
 // CHECK-NEXT: ret void





More information about the cfe-commits mailing list