From 50f089a6e1837cb81f8d1830bda6db619e422a2e Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Thu, 13 Dec 2012 23:37:17 +0000 Subject: [PATCH] Make sure the __invoke function for lambdas returns properly. Per bug report on IRC> git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@170160 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGClass.cpp | 2 ++ test/CodeGenCXX/lambda-expressions.cpp | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/CodeGen/CGClass.cpp b/lib/CodeGen/CGClass.cpp index b2225e48e3..9df8905bcd 100644 --- a/lib/CodeGen/CGClass.cpp +++ b/lib/CodeGen/CGClass.cpp @@ -1787,6 +1787,8 @@ void CodeGenFunction::EmitForwardingCallToLambda(const CXXRecordDecl *lambda, // If necessary, copy the returned value into the slot. if (!resultType->isVoidType() && returnSlot.isNull()) EmitReturnOfRValue(RV, resultType); + else + EmitBranchThroughCleanup(ReturnBlock); } void CodeGenFunction::EmitLambdaBlockInvokeBody() { diff --git a/test/CodeGenCXX/lambda-expressions.cpp b/test/CodeGenCXX/lambda-expressions.cpp index 19195c9dd2..e4bdf9202a 100644 --- a/test/CodeGenCXX/lambda-expressions.cpp +++ b/test/CodeGenCXX/lambda-expressions.cpp @@ -80,6 +80,15 @@ int g() { return [] { return r; } (); }; +// CHECK: define internal void @"_ZZ1hvEN3$_78__invokeEv"(%struct.A* noalias sret %agg.result) +// CHECK-NEXT: entry: +// CHECK-NEXT: call void @"_ZZ1hvENK3$_7clEv"(%struct.A* sret %agg.result, +// CHECK-NEXT: ret void +struct A { ~A(); }; +void h() { + A (*h)() = [] { return A(); }; +} + // CHECK: define internal i32 @"_ZZ1fvEN3$_58__invokeEii" // CHECK: store i32 // CHECK-NEXT: store i32