This revision was automatically updated to reflect the committed changes. Closed by commit rL348569: Fix thunks returning memptrs via sret by emitting also scalar return values… (authored by hans, committed by ).
Changed prior to commit: https://reviews.llvm.org/D55371?vs=176971&id=177135#toc Repository: rL LLVM CHANGES SINCE LAST ACTION https://reviews.llvm.org/D55371/new/ https://reviews.llvm.org/D55371 Files: cfe/trunk/lib/CodeGen/CGVTables.cpp cfe/trunk/lib/CodeGen/CodeGenFunction.cpp cfe/trunk/test/CodeGenCXX/thunk-returning-memptr.cpp Index: cfe/trunk/test/CodeGenCXX/thunk-returning-memptr.cpp =================================================================== --- cfe/trunk/test/CodeGenCXX/thunk-returning-memptr.cpp +++ cfe/trunk/test/CodeGenCXX/thunk-returning-memptr.cpp @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 -triple=i686 -emit-llvm -o - %s | FileCheck %s + + +struct X; +typedef void (X::*memptr)(); + +struct A { + virtual memptr f(); +}; + +struct B { + virtual memptr f(); +}; + +struct C : A, B { + C(); + memptr f() override __attribute__((noinline)) { return nullptr; }; +}; + +C::C() {} + +// Make sure the member pointer is returned from the thunk via the return slot. +// Because of the tail call, the return value cannot be copied into a local +// alloca. (PR39901) + +// CHECK-LABEL: define linkonce_odr void @_ZThn4_N1C1fEv({ i32, i32 }* noalias sret %agg.result, %struct.C* %this) +// CHECK: tail call void @_ZN1C1fEv({ i32, i32 }* sret %agg.result Index: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp =================================================================== --- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp +++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp @@ -1073,9 +1073,8 @@ // Count the implicit return. if (!endsWithReturn(D)) ++NumReturnExprs; - } else if (CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::Indirect && - !hasScalarEvaluationKind(CurFnInfo->getReturnType())) { - // Indirect aggregate return; emit returned value directly into sret slot. + } else if (CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::Indirect) { + // Indirect return; emit returned value directly into sret slot. // This reduces code size, and affects correctness in C++. auto AI = CurFn->arg_begin(); if (CurFnInfo->getReturnInfo().isSRetAfterThis()) Index: cfe/trunk/lib/CodeGen/CGVTables.cpp =================================================================== --- cfe/trunk/lib/CodeGen/CGVTables.cpp +++ cfe/trunk/lib/CodeGen/CGVTables.cpp @@ -350,8 +350,7 @@ : FPT->getReturnType(); ReturnValueSlot Slot; if (!ResultType->isVoidType() && - CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::Indirect && - !hasScalarEvaluationKind(CurFnInfo->getReturnType())) + CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::Indirect) Slot = ReturnValueSlot(ReturnValue, ResultType.isVolatileQualified()); // Now emit our call.
Index: cfe/trunk/test/CodeGenCXX/thunk-returning-memptr.cpp =================================================================== --- cfe/trunk/test/CodeGenCXX/thunk-returning-memptr.cpp +++ cfe/trunk/test/CodeGenCXX/thunk-returning-memptr.cpp @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 -triple=i686 -emit-llvm -o - %s | FileCheck %s + + +struct X; +typedef void (X::*memptr)(); + +struct A { + virtual memptr f(); +}; + +struct B { + virtual memptr f(); +}; + +struct C : A, B { + C(); + memptr f() override __attribute__((noinline)) { return nullptr; }; +}; + +C::C() {} + +// Make sure the member pointer is returned from the thunk via the return slot. +// Because of the tail call, the return value cannot be copied into a local +// alloca. (PR39901) + +// CHECK-LABEL: define linkonce_odr void @_ZThn4_N1C1fEv({ i32, i32 }* noalias sret %agg.result, %struct.C* %this) +// CHECK: tail call void @_ZN1C1fEv({ i32, i32 }* sret %agg.result Index: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp =================================================================== --- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp +++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp @@ -1073,9 +1073,8 @@ // Count the implicit return. if (!endsWithReturn(D)) ++NumReturnExprs; - } else if (CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::Indirect && - !hasScalarEvaluationKind(CurFnInfo->getReturnType())) { - // Indirect aggregate return; emit returned value directly into sret slot. + } else if (CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::Indirect) { + // Indirect return; emit returned value directly into sret slot. // This reduces code size, and affects correctness in C++. auto AI = CurFn->arg_begin(); if (CurFnInfo->getReturnInfo().isSRetAfterThis()) Index: cfe/trunk/lib/CodeGen/CGVTables.cpp =================================================================== --- cfe/trunk/lib/CodeGen/CGVTables.cpp +++ cfe/trunk/lib/CodeGen/CGVTables.cpp @@ -350,8 +350,7 @@ : FPT->getReturnType(); ReturnValueSlot Slot; if (!ResultType->isVoidType() && - CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::Indirect && - !hasScalarEvaluationKind(CurFnInfo->getReturnType())) + CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::Indirect) Slot = ReturnValueSlot(ReturnValue, ResultType.isVolatileQualified()); // Now emit our call.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits