Index: lib/CodeGen/CGBlocks.cpp =================================================================== --- lib/CodeGen/CGBlocks.cpp +++ lib/CodeGen/CGBlocks.cpp @@ -1450,9 +1450,12 @@ llvm::BasicBlock::iterator entry_ptr = Builder.GetInsertPoint(); --entry_ptr; - if (IsLambdaConversionToBlock) + if (IsLambdaConversionToBlock) { + // The lambda that's generated will emit a call to + // objc_autoreleaseReturnValue for us if necessary + AutoreleaseResult = false; EmitLambdaBlockInvokeBody(); - else { + } else { PGO.assignRegionCounters(GlobalDecl(blockDecl), fn); incrementProfileCounter(blockDecl->getBody()); EmitStmt(blockDecl->getBody()); Index: test/CodeGenObjCXX/arc-block-lambda-conversion.mm =================================================================== --- /dev/null +++ test/CodeGenObjCXX/arc-block-lambda-conversion.mm @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.12.0 -emit-llvm -fblocks -fobjc-arc -fobjc-runtime-has-weak -std=c++11 -O2 -o - %s | FileCheck %s + +void test0(id x) { + extern void test0_helper(id (^)(void)); + test0_helper([=]() { return x; }); + // CHECK-LABEL: define internal i8* @___Z5test0P11objc_object_block_invoke + // CHECK: {{%.*}} = tail call i8* @objc_retain(i8* [[T0:%.*]]) + // CHECK-NEXT: {{%.*}} = tail call i8* @objc_autoreleaseReturnValue(i8* [[T0]]) + // CHECK-NEXT: ret i8* [[T0]] +}