diff options
Diffstat (limited to 'clang/lib/CodeGen/CGBlocks.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGBlocks.cpp | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp index 8d82898fda9..6cf7f71ba5f 100644 --- a/clang/lib/CodeGen/CGBlocks.cpp +++ b/clang/lib/CodeGen/CGBlocks.cpp @@ -725,12 +725,13 @@ llvm::Value *CodeGenFunction::EmitBlockLiteral(const CGBlockInfo &blockInfo) { llvm::Constant *blockFn = CodeGenFunction(CGM, true).GenerateBlockFunction(CurGD, blockInfo, LocalDeclMap, - isLambdaConv); + isLambdaConv, + blockInfo.CanBeGlobal); blockFn = llvm::ConstantExpr::getBitCast(blockFn, VoidPtrTy); // If there is nothing to capture, we can emit this as a global block. if (blockInfo.CanBeGlobal) - return buildGlobalBlock(CGM, blockInfo, blockFn); + return CGM.getAddrOfGlobalBlockIfEmitted(blockInfo.BlockExpression); // Otherwise, we have to emit this as a local block. @@ -1114,17 +1115,14 @@ CodeGenModule::GetAddrOfGlobalBlock(const BlockExpr *BE, computeBlockInfo(*this, nullptr, blockInfo); // Using that metadata, generate the actual block function. - llvm::Constant *blockFn; { CodeGenFunction::DeclMapTy LocalDeclMap; - blockFn = CodeGenFunction(*this).GenerateBlockFunction(GlobalDecl(), - blockInfo, - LocalDeclMap, - false); + CodeGenFunction(*this).GenerateBlockFunction( + GlobalDecl(), blockInfo, LocalDeclMap, + /*IsLambdaConversionToBlock*/ false, /*BuildGlobalBlock*/ true); } - blockFn = llvm::ConstantExpr::getBitCast(blockFn, VoidPtrTy); - return buildGlobalBlock(*this, blockInfo, blockFn); + return getAddrOfGlobalBlockIfEmitted(BE); } static llvm::Constant *buildGlobalBlock(CodeGenModule &CGM, @@ -1226,7 +1224,8 @@ llvm::Function * CodeGenFunction::GenerateBlockFunction(GlobalDecl GD, const CGBlockInfo &blockInfo, const DeclMapTy &ldm, - bool IsLambdaConversionToBlock) { + bool IsLambdaConversionToBlock, + bool BuildGlobalBlock) { const BlockDecl *blockDecl = blockInfo.getBlockDecl(); CurGD = GD; @@ -1285,6 +1284,10 @@ CodeGenFunction::GenerateBlockFunction(GlobalDecl GD, fnLLVMType, llvm::GlobalValue::InternalLinkage, name, &CGM.getModule()); CGM.SetInternalFunctionAttributes(blockDecl, fn, fnInfo); + if (BuildGlobalBlock) + buildGlobalBlock(CGM, blockInfo, + llvm::ConstantExpr::getBitCast(fn, VoidPtrTy)); + // Begin generating the function. StartFunction(blockDecl, fnType->getReturnType(), fn, fnInfo, args, blockDecl->getLocation(), |