r330303 - [MS] Fix unprototyped thunk emission for incomplete return types

Reid Kleckner via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 18 16:21:32 PDT 2018


Author: rnk
Date: Wed Apr 18 16:21:32 2018
New Revision: 330303

URL: http://llvm.org/viewvc/llvm-project?rev=330303&view=rev
Log:
[MS] Fix unprototyped thunk emission for incomplete return types

Fixes PR37161

Modified:
    cfe/trunk/lib/CodeGen/CGVTables.cpp
    cfe/trunk/test/CodeGenCXX/ms-thunks-unprototyped.cpp

Modified: cfe/trunk/lib/CodeGen/CGVTables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVTables.cpp?rev=330303&r1=330302&r2=330303&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGVTables.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVTables.cpp Wed Apr 18 16:21:32 2018
@@ -233,11 +233,15 @@ void CodeGenFunction::StartThunk(llvm::F
   const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
   QualType ThisType = MD->getThisType(getContext());
   const FunctionProtoType *FPT = MD->getType()->getAs<FunctionProtoType>();
-  QualType ResultType = CGM.getCXXABI().HasThisReturn(GD)
-                            ? ThisType
-                            : CGM.getCXXABI().hasMostDerivedReturn(GD)
-                                  ? CGM.getContext().VoidPtrTy
-                                  : FPT->getReturnType();
+  QualType ResultType;
+  if (IsUnprototyped)
+    ResultType = CGM.getContext().VoidTy;
+  else if (CGM.getCXXABI().HasThisReturn(GD))
+    ResultType = ThisType;
+  else if (CGM.getCXXABI().hasMostDerivedReturn(GD))
+    ResultType = CGM.getContext().VoidPtrTy;
+  else
+    ResultType = FPT->getReturnType();
   FunctionArgList FunctionArgs;
 
   // Create the implicit 'this' parameter declaration.

Modified: cfe/trunk/test/CodeGenCXX/ms-thunks-unprototyped.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/ms-thunks-unprototyped.cpp?rev=330303&r1=330302&r2=330303&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/ms-thunks-unprototyped.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/ms-thunks-unprototyped.cpp Wed Apr 18 16:21:32 2018
@@ -24,11 +24,28 @@ struct B : virtual A {
 struct C : B { int c; };
 C c;
 
+// Do the same thing, but with an incomplete return type.
+struct B1 { virtual DoNotInstantiate<void> f() = 0; };
+struct B2 { virtual DoNotInstantiate<void> f() = 0; };
+struct S : B1, B2 { DoNotInstantiate<void> f() override; };
+S s;
+
+// CHECK: @"??_7S@@6BB2@@@" = linkonce_odr unnamed_addr constant
+// CHECK-SAME: void (%struct.S*, ...)* @"?f at S@@W7EAA?AU?$DoNotInstantiate at X@@XZ"
+
 // CHECK: @"??_7C@@6B@" = linkonce_odr unnamed_addr constant
 // CHECK-SAME: void (%struct.B*, ...)* @"?foo at B@@W7EAAXUIncomplete@@@Z"
 // CHECK-SAME: void (%struct.B*, ...)* @"?bar at B@@W7EAAXU?$DoNotInstantiate at H@@@Z"
 // CHECK-SAME: i32 (i8*, i32)* @"?baz at B@@W7EAAHU?$InstantiateLater at H@@@Z"
 
+
+// CHECK-LABEL: define linkonce_odr dso_local void @"?f at S@@W7EAA?AU?$DoNotInstantiate at X@@XZ"(%struct.S* %this, ...)
+// CHECK: %[[THIS_ADJ_i8:[^ ]*]] = getelementptr i8, i8* {{.*}}, i32 -8
+// CHECK: %[[THIS_ADJ:[^ ]*]] = bitcast i8* %[[THIS_ADJ_i8]] to %struct.S*
+// CHECK: musttail call void (%struct.S*, ...) {{.*}}@"?f at S@@UEAA?AU?$DoNotInstantiate at X@@XZ"
+// CHECK-SAME: (%struct.S* %[[THIS_ADJ]], ...)
+// CHECK: ret void
+
 // The thunks should have a -8 adjustment.
 
 // CHECK-LABEL: define linkonce_odr dso_local void @"?foo at B@@W7EAAXUIncomplete@@@Z"(%struct.B* %this, ...)




More information about the cfe-commits mailing list