diff options
Diffstat (limited to 'contrib/llvm/tools/clang/lib/CodeGen/CGBlocks.cpp')
-rw-r--r-- | contrib/llvm/tools/clang/lib/CodeGen/CGBlocks.cpp | 275 |
1 files changed, 138 insertions, 137 deletions
diff --git a/contrib/llvm/tools/clang/lib/CodeGen/CGBlocks.cpp b/contrib/llvm/tools/clang/lib/CodeGen/CGBlocks.cpp index 692f9a0..72fde9d 100644 --- a/contrib/llvm/tools/clang/lib/CodeGen/CGBlocks.cpp +++ b/contrib/llvm/tools/clang/lib/CodeGen/CGBlocks.cpp @@ -18,9 +18,9 @@ #include "CodeGenModule.h" #include "clang/AST/DeclObjC.h" #include "llvm/ADT/SmallSet.h" +#include "llvm/IR/CallSite.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/Module.h" -#include "llvm/Support/CallSite.h" #include <algorithm> #include <cstdio> @@ -30,9 +30,9 @@ using namespace CodeGen; CGBlockInfo::CGBlockInfo(const BlockDecl *block, StringRef name) : Name(name), CXXThisIndex(0), CanBeGlobal(false), NeedsCopyDispose(false), HasCXXObject(false), UsesStret(false), HasCapturedVariableLayout(false), - StructureType(0), Block(block), - DominatingIP(0) { - + StructureType(nullptr), Block(block), + DominatingIP(nullptr) { + // Skip asm prefix, if any. 'name' is usually taken directly from // the mangled name of the enclosing function. if (!name.empty() && name[0] == '\01') @@ -53,7 +53,7 @@ static llvm::Constant *buildCopyHelper(CodeGenModule &CGM, return CodeGenFunction(CGM).GenerateCopyHelperFunction(blockInfo); } -/// Build the helper function to dipose of a block. +/// Build the helper function to dispose of a block. static llvm::Constant *buildDisposeHelper(CodeGenModule &CGM, const CGBlockInfo &blockInfo) { return CodeGenFunction(CGM).GenerateDestroyHelperFunction(blockInfo); @@ -78,7 +78,13 @@ static llvm::Constant *buildBlockDescriptor(CodeGenModule &CGM, ASTContext &C = CGM.getContext(); llvm::Type *ulong = CGM.getTypes().ConvertType(C.UnsignedLongTy); - llvm::Type *i8p = CGM.getTypes().ConvertType(C.VoidPtrTy); + llvm::Type *i8p = NULL; + if (CGM.getLangOpts().OpenCL) + i8p = + llvm::Type::getInt8PtrTy( + CGM.getLLVMContext(), C.getTargetAddressSpace(LangAS::opencl_constant)); + else + i8p = CGM.getTypes().ConvertType(C.VoidPtrTy); SmallVector<llvm::Constant*, 6> elements; @@ -246,7 +252,7 @@ static bool isSafeForCXXConstantCapture(QualType type) { // Only records can be unsafe. if (!recordType) return true; - const CXXRecordDecl *record = cast<CXXRecordDecl>(recordType->getDecl()); + const auto *record = cast<CXXRecordDecl>(recordType->getDecl()); // Maintain semantics for classes with non-trivial dtors or copy ctors. if (!record->hasTrivialDestructor()) return false; @@ -269,7 +275,7 @@ static llvm::Constant *tryCaptureAsConstant(CodeGenModule &CGM, QualType type = var->getType(); // We can only do this if the variable is const. - if (!type.isConstQualified()) return 0; + if (!type.isConstQualified()) return nullptr; // Furthermore, in C++ we have to worry about mutable fields: // C++ [dcl.type.cv]p4: @@ -277,13 +283,13 @@ static llvm::Constant *tryCaptureAsConstant(CodeGenModule &CGM, // modified, any attempt to modify a const object during its // lifetime results in undefined behavior. if (CGM.getLangOpts().CPlusPlus && !isSafeForCXXConstantCapture(type)) - return 0; + return nullptr; // If the variable doesn't have any initializer (shouldn't this be // invalid?), it's not clear what we should do. Maybe capture as // zero? const Expr *init = var->getInit(); - if (!init) return 0; + if (!init) return nullptr; return CGM.EmitConstantInit(*var, CGF); } @@ -300,8 +306,8 @@ static void initializeForBlockHeader(CodeGenModule &CGM, CGBlockInfo &info, // The header is basically a 'struct { void *; int; int; void *; void *; }'. CharUnits ptrSize, ptrAlign, intSize, intAlign; - llvm::tie(ptrSize, ptrAlign) = C.getTypeInfoInChars(C.VoidPtrTy); - llvm::tie(intSize, intAlign) = C.getTypeInfoInChars(C.IntTy); + std::tie(ptrSize, ptrAlign) = C.getTypeInfoInChars(C.VoidPtrTy); + std::tie(intSize, intAlign) = C.getTypeInfoInChars(C.IntTy); // Are there crazy embedded platforms where this isn't true? assert(intSize <= ptrSize && "layout assumptions horribly violated"); @@ -366,15 +372,14 @@ static void computeBlockInfo(CodeGenModule &CGM, CodeGenFunction *CGF, layout.push_back(BlockLayoutChunk(tinfo.second, tinfo.first, Qualifiers::OCL_None, - 0, llvmType)); + nullptr, llvmType)); } // Next, all the block captures. - for (BlockDecl::capture_const_iterator ci = block->capture_begin(), - ce = block->capture_end(); ci != ce; ++ci) { - const VarDecl *variable = ci->getVariable(); + for (const auto &CI : block->captures()) { + const VarDecl *variable = CI.getVariable(); - if (ci->isByRef()) { + if (CI.isByRef()) { // We have to copy/dispose of the __block reference. info.NeedsCopyDispose = true; @@ -387,8 +392,7 @@ static void computeBlockInfo(CodeGenModule &CGM, CodeGenFunction *CGF, maxFieldAlign = std::max(maxFieldAlign, tinfo.second); layout.push_back(BlockLayoutChunk(tinfo.second, tinfo.first, - Qualifiers::OCL_None, - &*ci, llvmType)); + Qualifiers::OCL_None, &CI, llvmType)); continue; } @@ -422,7 +426,7 @@ static void computeBlockInfo(CodeGenModule &CGM, CodeGenFunction *CGF, lifetime = Qualifiers::OCL_Strong; // So do types that require non-trivial copy construction. - } else if (ci->hasCopyExpr()) { + } else if (CI.hasCopyExpr()) { info.NeedsCopyDispose = true; info.HasCXXObject = true; @@ -446,7 +450,7 @@ static void computeBlockInfo(CodeGenModule &CGM, CodeGenFunction *CGF, llvm::Type *llvmType = CGM.getTypes().ConvertTypeForMem(VT); - layout.push_back(BlockLayoutChunk(align, size, lifetime, &*ci, llvmType)); + layout.push_back(BlockLayoutChunk(align, size, lifetime, &CI, llvmType)); } // If that was everything, we're done here. @@ -581,14 +585,13 @@ static void enterBlockScope(CodeGenFunction &CGF, BlockDecl *block) { // Walk through the captures (in order) and find the ones not // captured by constant. - for (BlockDecl::capture_const_iterator ci = block->capture_begin(), - ce = block->capture_end(); ci != ce; ++ci) { + for (const auto &CI : block->captures()) { // Ignore __block captures; there's nothing special in the // on-stack block that we need to do for them. - if (ci->isByRef()) continue; + if (CI.isByRef()) continue; // Ignore variables that are constant-captured. - const VarDecl *variable = ci->getVariable(); + const VarDecl *variable = CI.getVariable(); CGBlockInfo::Capture &capture = blockInfo.getCapture(variable); if (capture.isConstant()) continue; @@ -664,7 +667,7 @@ void CodeGenFunction::destroyBlockInfos(CGBlockInfo *head) { CGBlockInfo *cur = head; head = cur->NextBlockInfo; delete cur; - } while (head != 0); + } while (head != nullptr); } /// Emit a block literal expression in the current function. @@ -679,7 +682,7 @@ llvm::Value *CodeGenFunction::EmitBlockLiteral(const BlockExpr *blockExpr) { } // Find the block info for this block and take ownership of it. - OwningPtr<CGBlockInfo> blockInfo; + std::unique_ptr<CGBlockInfo> blockInfo; blockInfo.reset(findAndRemoveBlockInfo(&FirstBlockInfo, blockExpr->getBlockDecl())); @@ -741,9 +744,8 @@ llvm::Value *CodeGenFunction::EmitBlockLiteral(const CGBlockInfo &blockInfo) { } // Next, captured variables. - for (BlockDecl::capture_const_iterator ci = blockDecl->capture_begin(), - ce = blockDecl->capture_end(); ci != ce; ++ci) { - const VarDecl *variable = ci->getVariable(); + for (const auto &CI : blockDecl->captures()) { + const VarDecl *variable = CI.getVariable(); const CGBlockInfo::Capture &capture = blockInfo.getCapture(variable); // Ignore constant captures. @@ -761,7 +763,7 @@ llvm::Value *CodeGenFunction::EmitBlockLiteral(const CGBlockInfo &blockInfo) { // Compute the address of the thing we're going to move into the // block literal. llvm::Value *src; - if (BlockInfo && ci->isNested()) { + if (BlockInfo && CI.isNested()) { // We need to use the capture from the enclosing block. const CGBlockInfo::Capture &enclosingCapture = BlockInfo->getCapture(variable); @@ -773,15 +775,15 @@ llvm::Value *CodeGenFunction::EmitBlockLiteral(const CGBlockInfo &blockInfo) { } else if (blockDecl->isConversionFromLambda()) { // The lambda capture in a lambda's conversion-to-block-pointer is // special; we'll simply emit it directly. - src = 0; + src = nullptr; } else { // Just look it up in the locals map, which will give us back a // [[type]]*. If that doesn't work, do the more elaborate DRE // emission. src = LocalDeclMap.lookup(variable); if (!src) { - DeclRefExpr declRef(const_cast<VarDecl*>(variable), - /*refersToEnclosing*/ ci->isNested(), type, + DeclRefExpr declRef(const_cast<VarDecl *>(variable), + /*refersToEnclosing*/ CI.isNested(), type, VK_LValue, SourceLocation()); src = EmitDeclRefLValue(&declRef).getAddress(); } @@ -791,9 +793,9 @@ llvm::Value *CodeGenFunction::EmitBlockLiteral(const CGBlockInfo &blockInfo) { // the block field. There's no need to chase the forwarding // pointer at this point, since we're building something that will // live a shorter life than the stack byref anyway. - if (ci->isByRef()) { + if (CI.isByRef()) { // Get a void* that points to the byref struct. - if (ci->isNested()) + if (CI.isNested()) src = Builder.CreateAlignedLoad(src, align.getQuantity(), "byref.capture"); else @@ -803,7 +805,7 @@ llvm::Value *CodeGenFunction::EmitBlockLiteral(const CGBlockInfo &blockInfo) { Builder.CreateAlignedStore(src, blockField, align.getQuantity()); // If we have a copy constructor, evaluate that into the block field. - } else if (const Expr *copyExpr = ci->getCopyExpr()) { + } else if (const Expr *copyExpr = CI.getCopyExpr()) { if (blockDecl->isConversionFromLambda()) { // If we have a lambda conversion, emit the expression // directly into the block instead. @@ -845,13 +847,14 @@ llvm::Value *CodeGenFunction::EmitBlockLiteral(const CGBlockInfo &blockInfo) { } else { // Fake up a new variable so that EmitScalarInit doesn't think // we're referring to the variable in its own initializer. - ImplicitParamDecl blockFieldPseudoVar(/*DC*/ 0, SourceLocation(), - /*name*/ 0, type); + ImplicitParamDecl blockFieldPseudoVar(getContext(), /*DC*/ nullptr, + SourceLocation(), /*name*/ nullptr, + type); // We use one of these or the other depending on whether the // reference is nested. DeclRefExpr declRef(const_cast<VarDecl*>(variable), - /*refersToEnclosing*/ ci->isNested(), type, + /*refersToEnclosing*/ CI.isNested(), type, VK_LValue, SourceLocation()); ImplicitCastExpr l2r(ImplicitCastExpr::OnStack, type, CK_LValueToRValue, @@ -862,7 +865,7 @@ llvm::Value *CodeGenFunction::EmitBlockLiteral(const CGBlockInfo &blockInfo) { } // Activate the cleanup if layout pushed one. - if (!ci->isByRef()) { + if (!CI.isByRef()) { EHScopeStack::stable_iterator cleanup = capture.getCleanup(); if (cleanup.isValid()) ActivateCleanupBlock(cleanup, blockInfo.DominatingIP); @@ -1023,7 +1026,7 @@ CodeGenModule::GetAddrOfGlobalBlock(const BlockExpr *blockExpr, blockInfo.BlockExpression = blockExpr; // Compute information about the layout, etc., of this block. - computeBlockInfo(*this, 0, blockInfo); + computeBlockInfo(*this, nullptr, blockInfo); // Using that metadata, generate the actual block function. llvm::Constant *blockFn; @@ -1097,7 +1100,7 @@ CodeGenFunction::GenerateBlockFunction(GlobalDecl GD, // to be local to this function as well, in case they're directly // referenced in a block. for (DeclMapTy::const_iterator i = ldm.begin(), e = ldm.end(); i != e; ++i) { - const VarDecl *var = dyn_cast<VarDecl>(i->first); + const auto *var = dyn_cast<VarDecl>(i->first); if (var && !var->hasLocalStorage()) LocalDeclMap[var] = i->second; } @@ -1112,35 +1115,32 @@ CodeGenFunction::GenerateBlockFunction(GlobalDecl GD, QualType selfTy = getContext().VoidPtrTy; IdentifierInfo *II = &CGM.getContext().Idents.get(".block_descriptor"); - ImplicitParamDecl selfDecl(const_cast<BlockDecl*>(blockDecl), + ImplicitParamDecl selfDecl(getContext(), const_cast<BlockDecl*>(blockDecl), SourceLocation(), II, selfTy); args.push_back(&selfDecl); // Now add the rest of the parameters. - for (BlockDecl::param_const_iterator i = blockDecl->param_begin(), - e = blockDecl->param_end(); i != e; ++i) - args.push_back(*i); + for (auto i : blockDecl->params()) + args.push_back(i); // Create the function declaration. const FunctionProtoType *fnType = blockInfo.getBlockExpr()->getFunctionType(); - const CGFunctionInfo &fnInfo = - CGM.getTypes().arrangeFunctionDeclaration(fnType->getResultType(), args, - fnType->getExtInfo(), - fnType->isVariadic()); - if (CGM.ReturnTypeUsesSRet(fnInfo)) + const CGFunctionInfo &fnInfo = CGM.getTypes().arrangeFreeFunctionDeclaration( + fnType->getReturnType(), args, fnType->getExtInfo(), + fnType->isVariadic()); + if (CGM.ReturnSlotInterferesWithArgs(fnInfo)) blockInfo.UsesStret = true; llvm::FunctionType *fnLLVMType = CGM.getTypes().GetFunctionType(fnInfo); - MangleBuffer name; - CGM.getBlockMangledName(GD, name, blockDecl); - llvm::Function *fn = - llvm::Function::Create(fnLLVMType, llvm::GlobalValue::InternalLinkage, - name.getString(), &CGM.getModule()); + StringRef name = CGM.getBlockMangledName(GD, blockDecl); + llvm::Function *fn = llvm::Function::Create( + fnLLVMType, llvm::GlobalValue::InternalLinkage, name, &CGM.getModule()); CGM.SetInternalFunctionAttributes(blockDecl, fn, fnInfo); // Begin generating the function. - StartFunction(blockDecl, fnType->getResultType(), fn, fnInfo, args, + StartFunction(blockDecl, fnType->getReturnType(), fn, fnInfo, args, + blockDecl->getLocation(), blockInfo.getBlockExpr()->getBody()->getLocStart()); // Okay. Undo some of what StartFunction did. @@ -1177,9 +1177,8 @@ CodeGenFunction::GenerateBlockFunction(GlobalDecl GD, } // Also force all the constant captures. - for (BlockDecl::capture_const_iterator ci = blockDecl->capture_begin(), - ce = blockDecl->capture_end(); ci != ce; ++ci) { - const VarDecl *variable = ci->getVariable(); + for (const auto &CI : blockDecl->captures()) { + const VarDecl *variable = CI.getVariable(); const CGBlockInfo::Capture &capture = blockInfo.getCapture(variable); if (!capture.isConstant()) continue; @@ -1201,8 +1200,14 @@ CodeGenFunction::GenerateBlockFunction(GlobalDecl GD, if (IsLambdaConversionToBlock) EmitLambdaBlockInvokeBody(); - else + else { + PGO.assignRegionCounters(blockDecl, fn); + RegionCounter Cnt = getPGORegionCounter(blockDecl->getBody()); + Cnt.beginRegion(Builder); EmitStmt(blockDecl->getBody()); + PGO.emitInstrumentationData(); + PGO.destroyRegionCounters(); + } // Remember where we were... llvm::BasicBlock *resume = Builder.GetInsertBlock(); @@ -1214,9 +1219,8 @@ CodeGenFunction::GenerateBlockFunction(GlobalDecl GD, // Emit debug information for all the DeclRefExprs. // FIXME: also for 'this' if (CGDebugInfo *DI = getDebugInfo()) { - for (BlockDecl::capture_const_iterator ci = blockDecl->capture_begin(), - ce = blockDecl->capture_end(); ci != ce; ++ci) { - const VarDecl *variable = ci->getVariable(); + for (const auto &CI : blockDecl->captures()) { + const VarDecl *variable = CI.getVariable(); DI->EmitLocation(Builder, variable->getLocation()); if (CGM.getCodeGenOpts().getDebugInfo() @@ -1238,7 +1242,7 @@ CodeGenFunction::GenerateBlockFunction(GlobalDecl GD, } // And resume where we left off. - if (resume == 0) + if (resume == nullptr) Builder.ClearInsertionPoint(); else Builder.SetInsertPoint(resume); @@ -1280,15 +1284,15 @@ CodeGenFunction::GenerateCopyHelperFunction(const CGBlockInfo &blockInfo) { ASTContext &C = getContext(); FunctionArgList args; - ImplicitParamDecl dstDecl(0, SourceLocation(), 0, C.VoidPtrTy); + ImplicitParamDecl dstDecl(getContext(), nullptr, SourceLocation(), nullptr, + C.VoidPtrTy); args.push_back(&dstDecl); - ImplicitParamDecl srcDecl(0, SourceLocation(), 0, C.VoidPtrTy); + ImplicitParamDecl srcDecl(getContext(), nullptr, SourceLocation(), nullptr, + C.VoidPtrTy); args.push_back(&srcDecl); - const CGFunctionInfo &FI = - CGM.getTypes().arrangeFunctionDeclaration(C.VoidTy, args, - FunctionType::ExtInfo(), - /*variadic*/ false); + const CGFunctionInfo &FI = CGM.getTypes().arrangeFreeFunctionDeclaration( + C.VoidTy, args, FunctionType::ExtInfo(), /*variadic=*/false); // FIXME: it would be nice if these were mergeable with things with // identical semantics. @@ -1304,13 +1308,13 @@ CodeGenFunction::GenerateCopyHelperFunction(const CGBlockInfo &blockInfo) { FunctionDecl *FD = FunctionDecl::Create(C, C.getTranslationUnitDecl(), SourceLocation(), - SourceLocation(), II, C.VoidTy, 0, - SC_Static, + SourceLocation(), II, C.VoidTy, + nullptr, SC_Static, false, false); // Create a scope with an artificial location for the body of this function. ArtificialLocation AL(*this, Builder); - StartFunction(FD, C.VoidTy, Fn, FI, args, SourceLocation()); + StartFunction(FD, C.VoidTy, Fn, FI, args); AL.Emit(); llvm::Type *structPtrTy = blockInfo.StructureType->getPointerTo(); @@ -1325,25 +1329,24 @@ CodeGenFunction::GenerateCopyHelperFunction(const CGBlockInfo &blockInfo) { const BlockDecl *blockDecl = blockInfo.getBlockDecl(); - for (BlockDecl::capture_const_iterator ci = blockDecl->capture_begin(), - ce = blockDecl->capture_end(); ci != ce; ++ci) { - const VarDecl *variable = ci->getVariable(); + for (const auto &CI : blockDecl->captures()) { + const VarDecl *variable = CI.getVariable(); QualType type = variable->getType(); const CGBlockInfo::Capture &capture = blockInfo.getCapture(variable); if (capture.isConstant()) continue; - const Expr *copyExpr = ci->getCopyExpr(); + const Expr *copyExpr = CI.getCopyExpr(); BlockFieldFlags flags; bool useARCWeakCopy = false; bool useARCStrongCopy = false; if (copyExpr) { - assert(!ci->isByRef()); + assert(!CI.isByRef()); // don't bother computing flags - } else if (ci->isByRef()) { + } else if (CI.isByRef()) { flags = BLOCK_FIELD_IS_BYREF; if (type.isObjCGCWeak()) flags |= BLOCK_FIELD_IS_WEAK; @@ -1400,7 +1403,7 @@ CodeGenFunction::GenerateCopyHelperFunction(const CGBlockInfo &blockInfo) { // storeStrong doesn't over-release) and then call storeStrong. // This is a workaround to not having an initStrong call. if (CGM.getCodeGenOpts().OptimizationLevel == 0) { - llvm::PointerType *ty = cast<llvm::PointerType>(srcValue->getType()); + auto *ty = cast<llvm::PointerType>(srcValue->getType()); llvm::Value *null = llvm::ConstantPointerNull::get(ty); Builder.CreateStore(null, dstField); EmitARCStoreStrongCall(dstField, srcValue, true); @@ -1423,7 +1426,7 @@ CodeGenFunction::GenerateCopyHelperFunction(const CGBlockInfo &blockInfo) { }; bool copyCanThrow = false; - if (ci->isByRef() && variable->getType()->getAsCXXRecordDecl()) { + if (CI.isByRef() && variable->getType()->getAsCXXRecordDecl()) { const Expr *copyExpr = CGM.getContext().getBlockVarCopyInits(variable); if (copyExpr) { @@ -1457,13 +1460,12 @@ CodeGenFunction::GenerateDestroyHelperFunction(const CGBlockInfo &blockInfo) { ASTContext &C = getContext(); FunctionArgList args; - ImplicitParamDecl srcDecl(0, SourceLocation(), 0, C.VoidPtrTy); + ImplicitParamDecl srcDecl(getContext(), nullptr, SourceLocation(), nullptr, + C.VoidPtrTy); args.push_back(&srcDecl); - const CGFunctionInfo &FI = - CGM.getTypes().arrangeFunctionDeclaration(C.VoidTy, args, - FunctionType::ExtInfo(), - /*variadic*/ false); + const CGFunctionInfo &FI = CGM.getTypes().arrangeFreeFunctionDeclaration( + C.VoidTy, args, FunctionType::ExtInfo(), /*variadic=*/false); // FIXME: We'd like to put these into a mergable by content, with // internal linkage. @@ -1478,12 +1480,12 @@ CodeGenFunction::GenerateDestroyHelperFunction(const CGBlockInfo &blockInfo) { FunctionDecl *FD = FunctionDecl::Create(C, C.getTranslationUnitDecl(), SourceLocation(), - SourceLocation(), II, C.VoidTy, 0, - SC_Static, + SourceLocation(), II, C.VoidTy, + nullptr, SC_Static, false, false); // Create a scope with an artificial location for the body of this function. ArtificialLocation AL(*this, Builder); - StartFunction(FD, C.VoidTy, Fn, FI, args, SourceLocation()); + StartFunction(FD, C.VoidTy, Fn, FI, args); AL.Emit(); llvm::Type *structPtrTy = blockInfo.StructureType->getPointerTo(); @@ -1496,21 +1498,20 @@ CodeGenFunction::GenerateDestroyHelperFunction(const CGBlockInfo &blockInfo) { CodeGenFunction::RunCleanupsScope cleanups(*this); - for (BlockDecl::capture_const_iterator ci = blockDecl->capture_begin(), - ce = blockDecl->capture_end(); ci != ce; ++ci) { - const VarDecl *variable = ci->getVariable(); + for (const auto &CI : blockDecl->captures()) { + const VarDecl *variable = CI.getVariable(); QualType type = variable->getType(); const CGBlockInfo::Capture &capture = blockInfo.getCapture(variable); if (capture.isConstant()) continue; BlockFieldFlags flags; - const CXXDestructorDecl *dtor = 0; + const CXXDestructorDecl *dtor = nullptr; bool useARCWeakDestroy = false; bool useARCStrongDestroy = false; - if (ci->isByRef()) { + if (CI.isByRef()) { flags = BLOCK_FIELD_IS_BYREF; if (type.isObjCGCWeak()) flags |= BLOCK_FIELD_IS_WEAK; @@ -1587,7 +1588,7 @@ public: : ByrefHelpers(alignment), Flags(flags) {} void emitCopy(CodeGenFunction &CGF, llvm::Value *destField, - llvm::Value *srcField) { + llvm::Value *srcField) override { destField = CGF.Builder.CreateBitCast(destField, CGF.VoidPtrTy); srcField = CGF.Builder.CreateBitCast(srcField, CGF.VoidPtrPtrTy); @@ -1602,14 +1603,14 @@ public: CGF.EmitNounwindRuntimeCall(fn, args); } - void emitDispose(CodeGenFunction &CGF, llvm::Value *field) { + void emitDispose(CodeGenFunction &CGF, llvm::Value *field) override { field = CGF.Builder.CreateBitCast(field, CGF.Int8PtrTy->getPointerTo(0)); llvm::Value *value = CGF.Builder.CreateLoad(field); CGF.BuildBlockRelease(value, Flags | BLOCK_BYREF_CALLER); } - void profileImpl(llvm::FoldingSetNodeID &id) const { + void profileImpl(llvm::FoldingSetNodeID &id) const override { id.AddInteger(Flags.getBitMask()); } }; @@ -1620,15 +1621,15 @@ public: ARCWeakByrefHelpers(CharUnits alignment) : ByrefHelpers(alignment) {} void emitCopy(CodeGenFunction &CGF, llvm::Value *destField, - llvm::Value *srcField) { + llvm::Value *srcField) override { CGF.EmitARCMoveWeak(destField, srcField); } - void emitDispose(CodeGenFunction &CGF, llvm::Value *field) { + void emitDispose(CodeGenFunction &CGF, llvm::Value *field) override { CGF.EmitARCDestroyWeak(field); } - void profileImpl(llvm::FoldingSetNodeID &id) const { + void profileImpl(llvm::FoldingSetNodeID &id) const override { // 0 is distinguishable from all pointers and byref flags id.AddInteger(0); } @@ -1641,7 +1642,7 @@ public: ARCStrongByrefHelpers(CharUnits alignment) : ByrefHelpers(alignment) {} void emitCopy(CodeGenFunction &CGF, llvm::Value *destField, - llvm::Value *srcField) { + llvm::Value *srcField) override { // Do a "move" by copying the value and then zeroing out the old // variable. @@ -1665,11 +1666,11 @@ public: store->setAlignment(Alignment.getQuantity()); } - void emitDispose(CodeGenFunction &CGF, llvm::Value *field) { + void emitDispose(CodeGenFunction &CGF, llvm::Value *field) override { CGF.EmitARCDestroyStrong(field, ARCImpreciseLifetime); } - void profileImpl(llvm::FoldingSetNodeID &id) const { + void profileImpl(llvm::FoldingSetNodeID &id) const override { // 1 is distinguishable from all pointers and byref flags id.AddInteger(1); } @@ -1682,7 +1683,7 @@ public: ARCStrongBlockByrefHelpers(CharUnits alignment) : ByrefHelpers(alignment) {} void emitCopy(CodeGenFunction &CGF, llvm::Value *destField, - llvm::Value *srcField) { + llvm::Value *srcField) override { // Do the copy with objc_retainBlock; that's all that // _Block_object_assign would do anyway, and we'd have to pass the // right arguments to make sure it doesn't get no-op'ed. @@ -1695,11 +1696,11 @@ public: store->setAlignment(Alignment.getQuantity()); } - void emitDispose(CodeGenFunction &CGF, llvm::Value *field) { + void emitDispose(CodeGenFunction &CGF, llvm::Value *field) override { CGF.EmitARCDestroyStrong(field, ARCImpreciseLifetime); } - void profileImpl(llvm::FoldingSetNodeID &id) const { + void profileImpl(llvm::FoldingSetNodeID &id) const override { // 2 is distinguishable from all pointers and byref flags id.AddInteger(2); } @@ -1716,20 +1717,20 @@ public: const Expr *copyExpr) : ByrefHelpers(alignment), VarType(type), CopyExpr(copyExpr) {} - bool needsCopy() const { return CopyExpr != 0; } + bool needsCopy() const override { return CopyExpr != nullptr; } void emitCopy(CodeGenFunction &CGF, llvm::Value *destField, - llvm::Value *srcField) { + llvm::Value *srcField) override { if (!CopyExpr) return; CGF.EmitSynthesizedCXXCopyCtor(destField, srcField, CopyExpr); } - void emitDispose(CodeGenFunction &CGF, llvm::Value *field) { + void emitDispose(CodeGenFunction &CGF, llvm::Value *field) override { EHScopeStack::stable_iterator cleanupDepth = CGF.EHStack.stable_begin(); CGF.PushDestructorCleanup(VarType, field); CGF.PopCleanupBlocks(cleanupDepth); } - void profileImpl(llvm::FoldingSetNodeID &id) const { + void profileImpl(llvm::FoldingSetNodeID &id) const override { id.AddPointer(VarType.getCanonicalType().getAsOpaquePtr()); } }; @@ -1745,16 +1746,16 @@ generateByrefCopyHelper(CodeGenFunction &CGF, QualType R = Context.VoidTy; FunctionArgList args; - ImplicitParamDecl dst(0, SourceLocation(), 0, Context.VoidPtrTy); + ImplicitParamDecl dst(CGF.getContext(), nullptr, SourceLocation(), nullptr, + Context.VoidPtrTy); args.push_back(&dst); - ImplicitParamDecl src(0, SourceLocation(), 0, Context.VoidPtrTy); + ImplicitParamDecl src(CGF.getContext(), nullptr, SourceLocation(), nullptr, + Context.VoidPtrTy); args.push_back(&src); - const CGFunctionInfo &FI = - CGF.CGM.getTypes().arrangeFunctionDeclaration(R, args, - FunctionType::ExtInfo(), - /*variadic*/ false); + const CGFunctionInfo &FI = CGF.CGM.getTypes().arrangeFreeFunctionDeclaration( + R, args, FunctionType::ExtInfo(), /*variadic=*/false); CodeGenTypes &Types = CGF.CGM.getTypes(); llvm::FunctionType *LTy = Types.GetFunctionType(FI); @@ -1771,11 +1772,11 @@ generateByrefCopyHelper(CodeGenFunction &CGF, FunctionDecl *FD = FunctionDecl::Create(Context, Context.getTranslationUnitDecl(), SourceLocation(), - SourceLocation(), II, R, 0, + SourceLocation(), II, R, nullptr, SC_Static, false, false); - CGF.StartFunction(FD, R, Fn, FI, args, SourceLocation()); + CGF.StartFunction(FD, R, Fn, FI, args); if (byrefInfo.needsCopy()) { llvm::Type *byrefPtrType = byrefType.getPointerTo(0); @@ -1819,13 +1820,12 @@ generateByrefDisposeHelper(CodeGenFunction &CGF, QualType R = Context.VoidTy; FunctionArgList args; - ImplicitParamDecl src(0, SourceLocation(), 0, Context.VoidPtrTy); + ImplicitParamDecl src(CGF.getContext(), nullptr, SourceLocation(), nullptr, + Context.VoidPtrTy); args.push_back(&src); - const CGFunctionInfo &FI = - CGF.CGM.getTypes().arrangeFunctionDeclaration(R, args, - FunctionType::ExtInfo(), - /*variadic*/ false); + const CGFunctionInfo &FI = CGF.CGM.getTypes().arrangeFreeFunctionDeclaration( + R, args, FunctionType::ExtInfo(), /*variadic=*/false); CodeGenTypes &Types = CGF.CGM.getTypes(); llvm::FunctionType *LTy = Types.GetFunctionType(FI); @@ -1843,10 +1843,10 @@ generateByrefDisposeHelper(CodeGenFunction &CGF, FunctionDecl *FD = FunctionDecl::Create(Context, Context.getTranslationUnitDecl(), SourceLocation(), - SourceLocation(), II, R, 0, + SourceLocation(), II, R, nullptr, SC_Static, false, false); - CGF.StartFunction(FD, R, Fn, FI, args, SourceLocation()); + CGF.StartFunction(FD, R, Fn, FI, args); if (byrefInfo.needsDispose()) { llvm::Value *V = CGF.GetAddrOfLocalVar(&src); @@ -1913,7 +1913,7 @@ CodeGenFunction::buildByrefHelpers(llvm::StructType &byrefType, if (const CXXRecordDecl *record = type->getAsCXXRecordDecl()) { const Expr *copyExpr = CGM.getContext().getBlockVarCopyInits(&var); - if (!copyExpr && record->hasTrivialDestructor()) return 0; + if (!copyExpr && record->hasTrivialDestructor()) return nullptr; CXXByrefHelpers byrefInfo(emission.Alignment, type, copyExpr); return ::buildByrefHelpers(CGM, byrefType, byrefValueIndex, byrefInfo); @@ -1921,7 +1921,7 @@ CodeGenFunction::buildByrefHelpers(llvm::StructType &byrefType, // Otherwise, if we don't have a retainable type, there's nothing to do. // that the runtime does extra copies. - if (!type->isObjCRetainableType()) return 0; + if (!type->isObjCRetainableType()) return nullptr; Qualifiers qs = type.getQualifiers(); @@ -1935,7 +1935,7 @@ CodeGenFunction::buildByrefHelpers(llvm::StructType &byrefType, // These are just bits as far as the runtime is concerned. case Qualifiers::OCL_ExplicitNone: case Qualifiers::OCL_Autoreleasing: - return 0; + return nullptr; // Tell the runtime that this is ARC __weak, called by the // byref routines. @@ -1969,7 +1969,7 @@ CodeGenFunction::buildByrefHelpers(llvm::StructType &byrefType, type->isObjCObjectPointerType()) { flags |= BLOCK_FIELD_IS_OBJECT; } else { - return 0; + return nullptr; } if (type.isObjCGCWeak()) @@ -2218,7 +2218,7 @@ namespace { llvm::Value *Addr; CallBlockRelease(llvm::Value *Addr) : Addr(Addr) {} - void Emit(CodeGenFunction &CGF, Flags flags) { + void Emit(CodeGenFunction &CGF, Flags flags) override { // Should we be passing FIELD_IS_WEAK here? CGF.BuildBlockRelease(Addr, BLOCK_FIELD_IS_BYREF); } @@ -2242,9 +2242,8 @@ static void configureBlocksRuntimeObject(CodeGenModule &CGM, llvm::Constant *C) { if (!CGM.getLangOpts().BlocksRuntimeOptional) return; - llvm::GlobalValue *GV = cast<llvm::GlobalValue>(C->stripPointerCasts()); - if (GV->isDeclaration() && - GV->getLinkage() == llvm::GlobalValue::ExternalLinkage) + auto *GV = cast<llvm::GlobalValue>(C->stripPointerCasts()); + if (GV->isDeclaration() && GV->hasExternalLinkage()) GV->setLinkage(llvm::GlobalValue::ExternalWeakLinkage); } @@ -2277,7 +2276,8 @@ llvm::Constant *CodeGenModule::getNSConcreteGlobalBlock() { return NSConcreteGlobalBlock; NSConcreteGlobalBlock = GetOrCreateLLVMGlobal("_NSConcreteGlobalBlock", - Int8PtrTy->getPointerTo(), 0); + Int8PtrTy->getPointerTo(), + nullptr); configureBlocksRuntimeObject(*this, NSConcreteGlobalBlock); return NSConcreteGlobalBlock; } @@ -2287,7 +2287,8 @@ llvm::Constant *CodeGenModule::getNSConcreteStackBlock() { return NSConcreteStackBlock; NSConcreteStackBlock = GetOrCreateLLVMGlobal("_NSConcreteStackBlock", - Int8PtrTy->getPointerTo(), 0); + Int8PtrTy->getPointerTo(), + nullptr); configureBlocksRuntimeObject(*this, NSConcreteStackBlock); return NSConcreteStackBlock; } |