From 54a33d7a27516e71b31dc2d0934a40893c53d917 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Wed, 18 Apr 2018 23:21:32 +0000 Subject: [PATCH] [MS] Fix unprototyped thunk emission for incomplete return types Fixes PR37161 llvm-svn: 330303 --- clang/lib/CodeGen/CGVTables.cpp | 14 +++++++++----- clang/test/CodeGenCXX/ms-thunks-unprototyped.cpp | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/clang/lib/CodeGen/CGVTables.cpp b/clang/lib/CodeGen/CGVTables.cpp index d063f03..7ac15ba 100644 --- a/clang/lib/CodeGen/CGVTables.cpp +++ b/clang/lib/CodeGen/CGVTables.cpp @@ -233,11 +233,15 @@ void CodeGenFunction::StartThunk(llvm::Function *Fn, GlobalDecl GD, const CXXMethodDecl *MD = cast(GD.getDecl()); QualType ThisType = MD->getThisType(getContext()); const FunctionProtoType *FPT = MD->getType()->getAs(); - 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. diff --git a/clang/test/CodeGenCXX/ms-thunks-unprototyped.cpp b/clang/test/CodeGenCXX/ms-thunks-unprototyped.cpp index b2ca5cb..0a232b9 100644 --- a/clang/test/CodeGenCXX/ms-thunks-unprototyped.cpp +++ b/clang/test/CodeGenCXX/ms-thunks-unprototyped.cpp @@ -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 f() = 0; }; +struct B2 { virtual DoNotInstantiate f() = 0; }; +struct S : B1, B2 { DoNotInstantiate f() override; }; +S s; + +// CHECK: @"??_7S@@6BB2@@@" = linkonce_odr unnamed_addr constant +// CHECK-SAME: void (%struct.S*, ...)* @"?f@S@@W7EAA?AU?$DoNotInstantiate@X@@XZ" + // CHECK: @"??_7C@@6B@" = linkonce_odr unnamed_addr constant // CHECK-SAME: void (%struct.B*, ...)* @"?foo@B@@W7EAAXUIncomplete@@@Z" // CHECK-SAME: void (%struct.B*, ...)* @"?bar@B@@W7EAAXU?$DoNotInstantiate@H@@@Z" // CHECK-SAME: i32 (i8*, i32)* @"?baz@B@@W7EAAHU?$InstantiateLater@H@@@Z" + +// CHECK-LABEL: define linkonce_odr dso_local void @"?f@S@@W7EAA?AU?$DoNotInstantiate@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@S@@UEAA?AU?$DoNotInstantiate@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@B@@W7EAAXUIncomplete@@@Z"(%struct.B* %this, ...) -- 2.7.4