Lines Matching +full:ignore +full:- +full:power +full:- +full:on +full:- +full:sel
1 //===---- CGObjC.cpp - Emit LLVM Code for Objective-C ---------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This contains code to emit Objective-C code as LLVM code.
11 //===----------------------------------------------------------------------===//
54 CGM.getObjCRuntime().GenerateConstantString(E->getString()).getPointer();
58 /// EmitObjCBoxedExpr - This routine generates code to call
67 const ObjCMethodDecl *BoxingMethod = E->getBoxingMethod();
68 const Expr *SubExpr = E->getSubExpr();
70 if (E->isExpressibleAsConstantInitializer()) {
72 return ConstEmitter.tryEmitAbstract(E, E->getType());
75 assert(BoxingMethod->isClassMethod() && "BoxingMethod must be a class method");
76 Selector Sel = BoxingMethod->getSelector();
82 const ObjCInterfaceDecl *ClassDecl = BoxingMethod->getClassInterface();
86 const ParmVarDecl *ArgDecl = *BoxingMethod->param_begin();
87 QualType ArgQT = ArgDecl->getType().getUnqualifiedType();
91 const QualType ValueType(SubExpr->getType().getCanonicalType());
92 if (ValueType->isObjCBoxableRecordType()) {
95 Address Temporary = CreateMemTemp(SubExpr->getType());
107 const ParmVarDecl *EncodingDecl = BoxingMethod->parameters()[1];
108 QualType EncodingQT = EncodingDecl->getType().getUnqualifiedType();
117 *this, ReturnValueSlot(), BoxingMethod->getReturnType(), Sel, Receiver,
120 ConvertType(E->getType()));
133 ALE ? ALE->getNumElements() : DLE->getNumElements();
140 llvm::Value *Ptr = EmitLoadOfScalar(LV, E->getBeginLoc());
141 cast<llvm::LoadInst>(Ptr)->setMetadata(
144 return Builder.CreateBitCast(Ptr, ConvertType(E->getType()));
172 const Expr *Rhs = ALE->getElement(i);
183 const Expr *Key = DLE->getKeyValueElement(i).Key;
190 const Expr *Value = DLE->getKeyValueElement(i).Value;
204 ObjCMethodDecl::param_const_iterator PI = MethodWithObjects->param_begin();
206 QualType ArgQT = argDecl->getType().getUnqualifiedType();
210 ArgQT = argDecl->getType().getUnqualifiedType();
214 ArgQT = argDecl->getType().getUnqualifiedType();
220 Selector Sel = MethodWithObjects->getSelector();
221 QualType ResultType = E->getType();
223 = ResultType->getAsObjCInterfacePointerType();
224 assert(InterfacePointerType && "Unexpected InterfacePointerType - null");
226 = InterfacePointerType->getObjectType()->getInterface();
232 *this, ReturnValueSlot(), MethodWithObjects->getReturnType(), Sel,
244 ConvertType(E->getType()));
248 return EmitObjCCollectionLiteral(E, E->getArrayWithObjectsMethod());
253 return EmitObjCCollectionLiteral(E, E->getDictWithObjectsMethod());
259 // Note that this implementation allows for non-constant strings to be passed
262 return CGM.getObjCRuntime().GetSelector(*this, E->getSelector());
267 return CGM.getObjCRuntime().GenerateProtocolRef(*this, E->getProtocol());
270 /// Adjust the type of an Objective-C object that doesn't match up due
275 if (!ExpT->isObjCRetainableType())
280 if (ExpLLVMTy == Result.getScalarVal()->getType())
289 /// returns-inner-pointer message.
292 switch (message->getReceiverKind()) {
297 const Expr *receiver = message->getInstanceReceiver();
301 if (opaque->getSourceExpr())
302 receiver = opaque->getSourceExpr()->IgnoreParens();
306 if (!ice || ice->getCastKind() != CK_LValueToRValue) return true;
307 receiver = ice->getSubExpr()->IgnoreParens();
311 if (opaque->getSourceExpr())
312 receiver = opaque->getSourceExpr()->IgnoreParens();
316 if (receiver->getType().getObjCLifetime() != Qualifiers::OCL_Strong)
324 const DeclRefExpr *declRef = dyn_cast<DeclRefExpr>(ice->getSubExpr());
326 const VarDecl *var = dyn_cast<VarDecl>(declRef->getDecl());
331 return (var->hasLocalStorage() &&
332 !var->hasAttr<ObjCPreciseLifetimeAttr>());
349 /// immediately loaded from an ARC __weak l-value.
351 assert(E->getType()->isObjCRetainableType());
352 E = E->IgnoreParens();
354 if (CE->getCastKind() == CK_LValueToRValue) {
355 if (CE->getSubExpr()->getType().getObjCLifetime() == Qualifiers::OCL_Weak)
356 return CE->getSubExpr();
368 /// message send, using it is a trade-off: it sacrifices a few cycles of
370 /// runtimes to detect and special-case classes that use "standard"
379 const CallArgList &Args, Selector Sel, const ObjCMethodDecl *method,
386 switch (Sel.getMethodFamily()) {
390 ResultType->isObjCObjectPointerType()) {
391 // [Foo alloc] -> objc_alloc(Foo) or
392 // [self alloc] -> objc_alloc(self)
393 if (Sel.isUnarySelector() && Sel.getNameForSlot(0) == "alloc")
395 // [Foo allocWithZone:nil] -> objc_allocWithZone(Foo) or
396 // [self allocWithZone:nil] -> objc_allocWithZone(self)
397 if (Sel.isKeywordSelector() && Sel.getNumArgs() == 1 &&
398 Args.size() == 1 && Args.front().getType()->isPointerType() &&
399 Sel.getNameForSlot(0) == "allocWithZone") {
410 if (ResultType->isObjCObjectPointerType() &&
417 if (ResultType->isObjCObjectPointerType() &&
424 if (ResultType->isVoidType() &&
440 Selector Sel, llvm::Value *Receiver, const CallArgList &Args,
445 Sel, Method, isClassMessage)) {
448 return GenerateMessageSend(CGF, Return, ResultType, Sel, Receiver, Args, OID,
455 if (!PD->isNonRuntimeProtocol()) {
456 const auto *Can = PD->getCanonicalDecl();
461 for (const auto *ParentPD : PD->protocols())
473 const auto *Can = It->getCanonicalDecl();
474 if (Can->isNonRuntimeProtocol())
480 // If there are no non-runtime protocols then we can just stop now.
484 // Else we have to search through the non-runtime protocol's inheritancy
486 // a non-runtime protocol without any parents. These are the "first-implied"
487 // protocols from a non-runtime protocol.
496 const auto *Can = PD->getCanonicalDecl();
498 Can->getImpliedProtocols(AllImpliedProtocols);
501 // Similar to above, walk the list of first-implied protocols to find the set
505 PD->getImpliedProtocols(AllImpliedProtocols);
508 // From the first-implied list we have to finish building the final protocol
509 // list. If a protocol in the first-implied list was already implied via some
522 /// 'objc_alloc_init(MyClass)'. This provides a code size improvement on the
531 Selector Sel = OME->getSelector();
532 if (OME->getReceiverKind() != ObjCMessageExpr::Instance ||
533 !OME->getType()->isObjCObjectPointerType() || !Sel.isUnarySelector() ||
534 Sel.getNameForSlot(0) != "init")
540 dyn_cast<ObjCMessageExpr>(OME->getInstanceReceiver()->IgnoreParenCasts());
543 Selector SubSel = SubOME->getSelector();
545 if (!SubOME->getType()->isObjCObjectPointerType() ||
550 switch (SubOME->getReceiverKind()) {
552 if (!SubOME->getInstanceReceiver()->getType()->isObjCClassType())
554 Receiver = CGF.EmitScalarExpr(SubOME->getInstanceReceiver());
558 QualType ReceiverType = SubOME->getClassReceiver();
559 const ObjCObjectType *ObjTy = ReceiverType->castAs<ObjCObjectType>();
560 const ObjCInterfaceDecl *ID = ObjTy->getInterface();
570 return CGF.EmitObjCAllocInit(Receiver, CGF.ConvertType(OME->getType()));
579 bool isDelegateInit = E->isDelegateInitCall();
581 const ObjCMethodDecl *method = E->getMethodDecl();
583 // If the method is -retain, and the receiver's being loaded from
585 if (method && E->getReceiverKind() == ObjCMessageExpr::Instance &&
586 method->getMethodFamily() == OMF_retain) {
587 if (auto lvalueExpr = findWeakLValue(E->getInstanceReceiver())) {
590 return AdjustObjCObjectType(*this, E->getType(), RValue::get(result));
595 return AdjustObjCObjectType(*this, E->getType(), RValue::get(*Val));
605 method->hasAttr<NSConsumesSelfAttr>());
614 switch (E->getReceiverKind()) {
616 ReceiverType = E->getInstanceReceiver()->getType();
617 isClassMessage = ReceiverType->isObjCClassType();
620 E->getInstanceReceiver());
624 Receiver = EmitScalarExpr(E->getInstanceReceiver());
628 ReceiverType = E->getClassReceiver();
629 OID = ReceiverType->castAs<ObjCObjectType>()->getInterface();
630 assert(OID && "Invalid Objective-C class message send");
637 ReceiverType = E->getSuperType();
643 ReceiverType = E->getSuperType();
654 // (i.e. retain+autorelease) of receivers of returns-inner-pointer
657 method->hasAttr<ObjCReturnsInnerPointerAttr>() &&
661 QualType ResultType = method ? method->getReturnType() : E->getType();
664 EmitCallArgs(Args, method, E->arguments(), /*AC*/AbstractCallee(method));
679 GetAddrOfLocalVar(cast<ObjCMethodDecl>(CurCodeDecl)->getSelfDecl());
685 // super is only valid in an Objective-C method
687 bool isCategoryImpl = isa<ObjCCategoryImplDecl>(OMD->getDeclContext());
689 E->getSelector(),
690 OMD->getClassInterface(),
699 *this, Return, ResultType, E->getSelector(), Receiver, Args, OID,
707 GetAddrOfLocalVar(cast<ObjCMethodDecl>(CurCodeDecl)->getSelfDecl());
718 return AdjustObjCObjectType(*this, E->getType(), result);
726 const ObjCImplDecl *impl = cast<ObjCImplDecl>(method->getDeclContext());
727 const ObjCInterfaceDecl *iface = impl->getClassInterface();
728 if (!iface->getSuperClass()) return;
738 method->getSelector(),
749 /// StartObjCMethod - Begin emission of an ObjCMethod. This generates
754 SourceLocation StartLoc = OMD->getBeginLoc();
757 if (OMD->hasAttr<NoDebugAttr>())
763 if (OMD->isDirectMethod()) {
764 Fn->setVisibility(llvm::Function::HiddenVisibility);
771 args.push_back(OMD->getSelfDecl());
772 if (!OMD->isDirectMethod())
773 args.push_back(OMD->getCmdDecl());
775 args.append(OMD->param_begin(), OMD->param_end());
778 CurEHLocation = OMD->getEndLoc();
780 StartFunction(OMD, OMD->getReturnType(), Fn, FI, args,
781 OMD->getLocation(), StartLoc);
783 if (OMD->isDirectMethod()) {
785 // on entry.
793 OMD->isInstanceMethod() &&
794 OMD->getSelector().isUnarySelector()) {
796 OMD->getSelector().getIdentifierInfoForSlot(0);
797 if (ident->isStr("dealloc"))
805 /// Generate an Objective-C method. An Objective-C method is a C function with
808 StartObjCMethod(OMD, OMD->getClassInterface());
810 assert(isa<CompoundStmt>(OMD->getBody()));
811 incrementProfileCounter(OMD->getBody());
812 EmitCompoundStmtWithoutScope(*cast<CompoundStmt>(OMD->getBody()));
813 FinishFunction(OMD->getBodyRBrace());
816 /// emitStructGetterCall - Call the runtime function to load a property
834 CharUnits size = CGF.getContext().getTypeSizeInChars(ivar->getType());
849 // FIXME: Allow unaligned atomic load/store on x86. (It is not
858 // ARM has 8-byte atomic accesses, but it's not clear whether we
859 // want to rely on them here.
885 /// lvalue-to-rvalue expressions.
919 const ObjCPropertyDecl *prop = propImpl->getPropertyDecl();
920 ObjCPropertyDecl::SetterKind setterKind = prop->getSetterKind();
923 IsAtomic = prop->isAtomic();
927 ObjCIvarDecl *ivar = propImpl->getPropertyIvarDecl();
928 QualType ivarType = ivar->getType();
943 // In GC-only, there's nothing special that needs to be done.
947 // In ARC, if the property is non-atomic, use expression emission,
983 // Properties on bitfield ivars need to be emitted using expression
985 if (ivar->isBitField()) {
990 // GC-qualified or ARC-qualified ivars need to be emitted as
1002 if (const RecordType *recordType = ivarType->getAs<RecordType>())
1003 HasStrong = recordType->getDecl()->hasObjectMember();
1013 // Otherwise, this is target-dependent and based on the size and
1016 // If the size of the ivar is not a power of two, give up. We don't
1017 // want to get into the business of doing compare-and-swaps.
1045 /// Generate an Objective-C property getter function.
1053 ObjCMethodDecl *OMD = PID->getGetterMethodDecl();
1055 StartObjCMethod(OMD, IMP->getClassInterface());
1059 FinishFunction(OMD->getEndLoc());
1063 const Expr *getter = propImpl->getGetterCXXConstructor();
1070 // reference, in which case the result will be a gl-value. We should
1071 // treat this as a non-trivial operation.
1072 if (getter->isGLValue())
1075 // If we selected a trivial copy-constructor, we're okay.
1077 return (construct->getConstructor()->isTrivial());
1085 /// emitCPPObjectAtomicGetterCall - Call the runtime function to
1115 // emitCmdValueForGetterSetterBody - Handle emitting the load necessary for
1119 // never load one. For non-direct methods, this emits a load of the implicit
1123 if (MD->isDirectMethod()) {
1131 return CGF.Builder.CreateLoad(CGF.GetAddrOfLocalVar(MD->getCmdDecl()), "cmd");
1140 ObjCIvarDecl *ivar = propImpl->getPropertyIvarDecl();
1142 if (ivar->getType().isNonTrivialToPrimitiveCopy() == QualType::PCK_Struct) {
1146 LValue Dst = MakeAddrLValue(ReturnValue, ivar->getType());
1149 ObjCIvarDecl *ivar = propImpl->getPropertyIvarDecl();
1156 // If there's a non-trivial 'get' expression, we just have to emit that.
1160 propImpl->getGetterCXXConstructor(),
1165 ObjCIvarDecl *ivar = propImpl->getPropertyIvarDecl();
1172 const ObjCPropertyDecl *prop = propImpl->getPropertyDecl();
1173 QualType propType = prop->getType();
1174 ObjCMethodDecl *getterMethod = propImpl->getGetterMethodDecl();
1180 // We don't need to do anything for a zero-size struct.
1195 load->setAtomic(llvm::AtomicOrdering::Unordered);
1200 llvm::Type *retTy = ConvertType(getterMethod->getReturnType());
1218 CGM.ErrorUnsupported(propImpl, "Obj-C getter requiring atomic copy");
1223 // Return (ivar-type) objc_getProperty((id) self, _cmd, offset, true).
1229 EmitIvarOffsetAsPointerDiff(classImpl->getClassInterface(), ivar);
1245 call->setTailCall();
1252 getTypes().ConvertType(getterMethod->getReturnType())));
1271 QualType ivarType = ivar->getType();
1281 // that's not necessarily the same as "on the stack", so
1289 if (propType->isReferenceType()) {
1308 value, ConvertType(GetterMethodDecl->getReturnType()));
1322 /// emitStructSetterCall - Call the runtime function to store the value
1338 ParmVarDecl *argVar = *OMD->param_begin();
1340 argVar->getType().getNonReferenceType(), VK_LValue,
1347 CGF.CGM.getSize(CGF.getContext().getTypeSizeInChars(ivar->getType()));
1364 /// emitCPPObjectAtomicSetterCall - Call the runtime function to store
1366 /// the Cpp API for atomic Cpp objects with non-trivial copy assignment.
1382 ParmVarDecl *argVar = *OMD->param_begin();
1384 argVar->getType().getNonReferenceType(), VK_LValue,
1402 Expr *setter = PID->getSetterCXXAssignment();
1409 // This also implies that there's nothing non-trivial going on with
1415 = dyn_cast_or_null<FunctionDecl>(call->getCalleeDecl()))
1416 if (callee->isTrivial())
1435 ObjCIvarDecl *ivar = propImpl->getPropertyIvarDecl();
1436 ObjCMethodDecl *setterMethod = propImpl->getSetterMethodDecl();
1438 if (ivar->getType().isNonTrivialToPrimitiveCopy() == QualType::PCK_Struct) {
1439 ParmVarDecl *PVD = *setterMethod->param_begin();
1445 LValue Src = MakeAddrLValue(GetAddrOfLocalVar(PVD), ivar->getType());
1457 // non-trivial.
1460 // If non-atomic, assignment is called directly.
1461 EmitStmt(propImpl->getSetterCXXAssignment());
1472 // We don't need to do anything for a zero-size struct.
1476 Address argAddr = GetAddrOfLocalVar(*setterMethod->param_begin());
1495 store->setAtomic(llvm::AtomicOrdering::Unordered);
1510 CGM.ErrorUnsupported(propImpl, "Obj-C optimized setter - NYI");
1517 CGM.ErrorUnsupported(propImpl, "Obj-C setter requiring atomic copy");
1523 // <is-atomic>, <is-copy>).
1528 EmitIvarOffsetAsPointerDiff(classImpl->getClassInterface(), ivar);
1529 Address argAddr = GetAddrOfLocalVar(*setterMethod->param_begin());
1568 ValueDecl *selfDecl = setterMethod->getSelfDecl();
1569 DeclRefExpr self(getContext(), selfDecl, false, selfDecl->getType(),
1571 ImplicitCastExpr selfLoad(ImplicitCastExpr::OnStack, selfDecl->getType(),
1574 ObjCIvarRefExpr ivarRef(ivar, ivar->getType().getNonReferenceType(),
1578 ParmVarDecl *argDecl = *setterMethod->param_begin();
1579 QualType argType = argDecl->getType().getNonReferenceType();
1587 // Objective-C pointer types, we can always bit cast the RHS in these cases.
1588 // The following absurdity is just to ensure well-formed IR.
1590 if (ivarRef.getType()->isObjCObjectPointerType()) {
1591 if (argLoad.getType()->isObjCObjectPointerType())
1593 else if (argLoad.getType()->isBlockPointerType())
1597 } else if (ivarRef.getType()->isBlockPointerType()) {
1598 if (argLoad.getType()->isBlockPointerType())
1602 } else if (ivarRef.getType()->isPointerType()) {
1604 } else if (argLoad.getType()->isAtomicType() &&
1605 !ivarRef.getType()->isAtomicType()) {
1607 } else if (!argLoad.getType()->isAtomicType() &&
1608 ivarRef.getType()->isAtomicType()) {
1624 /// Generate an Objective-C property setter function.
1632 ObjCMethodDecl *OMD = PID->getSetterMethodDecl();
1634 StartObjCMethod(OMD, IMP->getClassInterface());
1638 FinishFunction(OMD->getEndLoc());
1658 CGF.emitDestroy(lvalue.getAddress(), ivar->getType(), destroyer,
1678 const ObjCInterfaceDecl *iface = impl->getClassInterface();
1679 for (const ObjCIvarDecl *ivar = iface->all_declared_ivar_begin();
1680 ivar; ivar = ivar->getNextIvar()) {
1681 QualType type = ivar->getType();
1711 MD->createImplicitParams(CGM.getContext(), IMP->getClassInterface());
1712 StartObjCMethod(MD, IMP->getClassInterface());
1719 for (const auto *IvarInit : IMP->inits()) {
1720 FieldDecl *Field = IvarInit->getAnyMember();
1724 EmitAggExpr(IvarInit->getInit(),
1745 VarDecl *Self = cast<ObjCMethodDecl>(CurFuncDecl)->getSelfDecl();
1748 Self->getType(), VK_LValue, SourceLocation());
1754 ImplicitParamDecl *selfDecl = OMD->getSelfDecl();
1756 getContext().getCanonicalType(selfDecl->getType()));
1757 return PTy->getPointeeType();
1764 CGM.ErrorUnsupported(&S, "Obj-C fast enumeration for this runtime");
1772 DI->EmitLexicalBlockStart(Builder, S.getSourceRange().getBegin());
1779 variable = EmitAutoVarAlloca(*cast<VarDecl>(SD->getSingleDecl()));
1810 EmitObjCConsumeObject(S.getCollection()->getType(), Collection);
1822 // The first argument is a temporary of the enumeration-state type.
1874 getPointerAlign(), "forcoll.initial-mutations");
1877 // fresh, non-empty batch of objects.
1883 index->addIncoming(zero, LoopInitBB);
1887 count->addIncoming(initialBufferLimit, LoopInitBB);
1905 // If so, call the enumeration-mutation function.
1930 const VarDecl *D = cast<VarDecl>(SD->getSingleDecl());
1932 D->getType(), VK_LValue, SourceLocation());
1934 elementType = D->getType();
1937 if (D->isARCPseudoStrong())
1941 elementType = cast<Expr>(S.getElement())->getType();
1967 elementType->getAsObjCInterfacePointerType();
1969 ObjPtrTy ? ObjPtrTy->getInterfaceType() : nullptr;
1973 assert(InterfaceTy->getDecl() && "No decl for ObjC interface type");
1977 CGM.getObjCRuntime().GetClass(*this, InterfaceTy->getDecl());
1998 // Make sure we have an l-value. Yes, this gets evaluated every
2034 // Set the branch weights based on the simplifying assumption that this is
2035 // like a while-loop, i.e., ignoring that the false branch fetches more
2041 index->addIncoming(indexPlusOne, AfterBody.getBlock());
2042 count->addIncoming(count, AfterBody.getBlock());
2056 index->addIncoming(zero, Builder.GetInsertBlock());
2057 count->addIncoming(refetchCount, Builder.GetInsertBlock());
2074 DI->EmitLexicalBlockEnd(Builder, S.getSourceRange().getEnd());
2099 // Releases at the end of the full-expression are imprecise.
2106 /// release at the end of the full-expression.
2148 F->setLinkage(llvm::Function::ExternalWeakLinkage);
2167 /// where a null input causes a no-op and returns null.
2179 llvm::Type *origType = returnType ? returnType : value->getType();
2184 call->setTailCallKind(tailKind);
2208 assert(addr.getElementType() == value->getType());
2213 llvm::Type *origType = value->getType();
2243 /// where a null input causes a no-op and returns null.
2260 f->addFnAttr(llvm::Attribute::NonLazyBind);
2264 llvm::Type *origType = returnType ? returnType : value->getType();
2270 // Mark calls to objc_autorelease as tail on the assumption that methods
2271 // overriding autorelease do not touch anything on the stack.
2274 Call->setTailCall();
2280 /// Produce the code to do a retain. Based on the type, calls one of:
2284 if (type->isBlockPointerType())
2301 /// \param mandatory - If false, emit the call with metadata
2317 = cast<llvm::CallInst>(result->stripPointerCasts());
2318 assert(call->getCalledOperand() ==
2321 call->setMetadata("clang.arc.copy_on_escape",
2341 // Otherwise, at -O0, build an inline asm that we're going to call
2349 // If we're at -O1 and above, we don't want to litter the code
2362 // Call the marker asm if we made one, which we do only at -O0.
2375 // optimization level isn't -O0 since global-isel, which is currently run at
2376 // -O0, doesn't know about the operand bundle.
2388 // FIXME: Do this on all targets and at -O0 too. This can be enabled only if
2397 newCall->copyMetadata(*oldCall);
2398 oldCall->replaceAllUsesWith(newCall);
2399 oldCall->eraseFromParent();
2421 /// Claim a possibly-autoreleased return value at +0. This is only
2422 /// valid to do in contexts which do not rely on the retain to keep
2450 call->setMetadata("clang.imprecise_release",
2457 /// At -O0, emit a call to store 'null' into the address;
2461 /// At -O1 and above, just load and call objc_release.
2481 assert(addr.getElementType() == value->getType());
2503 bool isBlock = type->isBlockPointerType();
2505 // Use a store barrier at -O0 unless this is a block type or the
2567 if (!type->isBlockPointerType())
2572 llvm::Type *origType = value->getType();
2689 assert(value->getType() == Int8PtrTy);
2716 /// init is declared as: - (id) init; in its NSObject super class.
2834 f->addFnAttr(llvm::Attribute::NonLazyBind);
2844 call->setMetadata("clang.imprecise_release",
2908 e = e->IgnoreParens();
2909 QualType type = e->getType();
2914 if (e->isXValue() &&
2930 // As a very special optimization, in ARC++, if the l-value is the
2931 // result of a non-volatile assignment, do a simple retain of the
2937 cast<BinaryOperator>(e)->getOpcode() == BO_Assign)
2941 // loading it because we are not guaranteed to have an l-value. One of such
2942 // cases is DeclRefExpr referencing non-odr-used constant-evaluated variable.
2973 CGF.Builder.SetInsertPoint(call->getParent(),
2978 llvm::BasicBlock *BB = invoke->getNormalDest();
2979 CGF.Builder.SetInsertPoint(BB, BB->begin());
2982 // Bitcasts can arise because of related-result returns. Rewrite
2985 // Change the insert point to avoid emitting the fall-back call after the
2987 CGF.Builder.SetInsertPoint(bitcast->getParent(), bitcast->getIterator());
2988 llvm::Value *operand = bitcast->getOperand(0);
2990 bitcast->setOperand(0, operand);
2994 if (phi && phi->getNumIncomingValues() == 2 &&
2995 isa<llvm::ConstantPointerNull>(phi->getIncomingValue(1)) &&
2996 isa<llvm::CallBase>(phi->getIncomingValue(0))) {
2999 llvm::Value *inVal = phi->getIncomingValue(0);
3001 phi->setIncomingValue(0, inVal);
3004 // Generic fall-back case.
3005 // Retain using the non-block variant: we never need to do a copy
3050 return EmitObjCConsumeObject(E->getType(), value);
3055 /// objc_retain_block on the result of the given expression, or
3058 assert(e->getType()->isBlockPointerType());
3059 e = e->IgnoreParens();
3067 switch (cast->getCastKind()) {
3078 return shouldEmitSeparateBlockRetain(cast->getSubExpr());
3134 const Expr *resultExpr = E->getResultExpr();
3139 i = E->semantics_begin(), e = E->semantics_end(); i != e; ++i) {
3148 // If this semantic is the result of the pseudo-object
3152 result = asImpl().visit(ov->getSourceExpr());
3158 opaqueData = OVMA::bind(CGF, ov, ov->getSourceExpr());
3188 switch (e->getCastKind()) {
3190 // No-op casts don't change the type, so we just ignore them.
3192 return asImpl().visit(e->getSubExpr());
3199 llvm::Type *resultType = CGF.ConvertType(e->getType());
3200 assert(e->getSubExpr()->getType()->hasPointerRepresentation());
3201 Result result = asImpl().visit(e->getSubExpr());
3207 return asImpl().visitLValueToRValue(e->getSubExpr());
3209 return asImpl().visitConsumeObject(e->getSubExpr());
3211 return asImpl().visitExtendBlockObject(e->getSubExpr());
3213 return asImpl().visitReclaimReturnedObject(e->getSubExpr());
3224 switch (e->getOpcode()) {
3226 CGF.EmitIgnoredExpr(e->getLHS());
3228 return asImpl().visit(e->getRHS());
3240 switch (e->getLHS()->getType().getObjCLifetime()) {
3266 Result result = asImpl().visit(e->getRHS());
3270 CGF.EmitCheckedLValue(e->getLHS(), CodeGenFunction::TCK_Store);
3295 /// The general expression-emission logic.
3298 // We should *never* see a nested full-expression here, because if
3300 // out the full-expression. This isn't as important in the unsafe
3305 e = e->IgnoreParens();
3317 // For calls and message sends, use the retained-call logic.
3319 // returns-retained expression that *isn't* surrounded by
3323 !cast<ObjCMessageExpr>(e)->isDelegateInitCall())) {
3326 // Look through pseudo-object expressions.
3367 // Avoid the block-retain if this is a block literal that doesn't need to be
3370 e->getBlockDecl()->canAvoidCopyToHeap())
3375 /// Block extends are net +0. Naively, we could just recurse on
3381 // If we can't safely assume the sub-expression will produce a
3382 // block-copied value, emit the sub-expression at +0.
3386 // Otherwise, try to emit the sub-expression at +1 recursively.
3417 // TODO: maybe special-case visitBinAssignWeak?
3443 /// EmitARCRetainScalarExpr - Semantically equivalent to
3444 /// EmitARCRetainObject(e->getType(), EmitScalarExpr(e)), but making a
3445 /// best-effort attempt to peephole expressions that naturally produce
3448 // The retain needs to happen within the full-expression.
3451 return EmitARCRetainScalarExpr(cleanups->getSubExpr());
3457 value = EmitARCRetain(e->getType(), value);
3463 // The retain needs to happen within the full-expression.
3466 return EmitARCRetainAutoreleaseScalarExpr(cleanups->getSubExpr());
3474 value = EmitARCRetainAutorelease(e->getType(), value);
3493 return EmitObjCConsumeObject(e->getType(), result);
3499 // Do so before running any cleanups for the full-expression.
3504 // Otherwise, use the normal scalar-expression emission. The
3536 return CGF.EmitObjCConsumeObject(e->getType(), value);
3568 /// EmitARCUnsafeUnretainedScalarExpr - Semantically equivalent to
3573 // Look through full-expressions.
3576 return emitARCUnsafeUnretainedScalarExpr(*this, cleanups->getSubExpr());
3589 value = EmitARCUnsafeUnretainedScalarExpr(e->getRHS());
3591 value = EmitScalarExpr(e->getRHS());
3595 LValue lvalue = EmitLValue(e->getLHS());
3605 TryEmitResult result = tryEmitARCRetainScalarExpr(*this, e->getRHS());
3610 // If we didn't emit a retained object, and the l-value is of block
3611 // type, then we need to emit the block-retain immediately in case
3612 // it invalidates the l-value.
3613 if (!hasImmediateRetain && e->getType()->isBlockPointerType()) {
3618 LValue lvalue = EmitLValue(e->getLHS());
3634 llvm::Value *value = EmitARCRetainAutoreleaseScalarExpr(e->getRHS());
3635 LValue lvalue = EmitLValue(e->getLHS());
3649 DI->EmitLexicalBlockStart(Builder, S.getLBracLoc());
3665 DI->EmitLexicalBlockEnd(Builder, S.getRBracLoc());
3668 /// EmitExtendGCLifetime - Given a pointer to an Objective-C object,
3682 /// GenerateObjCAtomicSetterCopyHelperFunction - Given a c++ object type with
3683 /// non-trivial copy assignment function, produce following helper function.
3689 const ObjCPropertyDecl *PD = PID->getPropertyDecl();
3690 if ((!(PD->getPropertyAttributes() & ObjCPropertyAttribute::kind_atomic)))
3693 QualType Ty = PID->getPropertyIvarDecl()->getType();
3708 if (!Ty->isRecordType())
3713 assert(PID->getSetterCXXAssignment() && "SetterCXXAssignment - null");
3747 FD->setParams(Params);
3765 C, &DstExpr, UO_Deref, DestTy->getPointeeType(), VK_LValue, OK_Ordinary,
3770 C, &SrcExpr, UO_Deref, SrcTy->getPointeeType(), VK_LValue, OK_Ordinary,
3774 CallExpr *CalleeExp = cast<CallExpr>(PID->getSetterCXXAssignment());
3776 C, OO_Equal, CalleeExp->getCallee(), Args, DestTy->getPointeeType(),
3789 const ObjCPropertyDecl *PD = PID->getPropertyDecl();
3790 if ((!(PD->getPropertyAttributes() & ObjCPropertyAttribute::kind_atomic)))
3793 QualType Ty = PD->getType();
3806 if (!Ty->isRecordType())
3811 assert(PID->getGetterCXXConstructor() && "getGetterCXXConstructor - null");
3845 FD->setParams(Params);
3864 C, &SrcExpr, UO_Deref, SrcTy->getPointeeType(), VK_LValue, OK_Ordinary,
3868 cast<CXXConstructExpr>(PID->getGetterCXXConstructor());
3872 ConstructorArgs.append(std::next(CXXConstExpr->arg_begin()),
3873 CXXConstExpr->arg_end());
3877 CXXConstExpr->getConstructor(),
3878 CXXConstExpr->isElidable(),
3880 CXXConstExpr->hadMultipleCandidates(),
3881 CXXConstExpr->isListInitialization(),
3882 CXXConstExpr->isStdInitListInitialization(),
3883 CXXConstExpr->requiresZeroInitialization(),
3884 CXXConstExpr->getConstructionKind(),
3892 getContext().getTypeAlignInChars(TheCXXConstructExpr->getType());
3954 // Note: we intend to support multi-platform version checks, so reserve
4042 // @available requires CoreFoundation only on Darwin.
4045 // @available doesn't need Foundation on macOS 10.15+, iOS/tvOS 13+, or
4050 // Add -framework CoreFoundation to the linker commands. We still want to
4055 llvm::Metadata *Args[2] = {llvm::MDString::get(Context, "-framework"),
4070 cast<llvm::Function>(CFLinkCheckFuncRef.getCallee()->stripPointerCasts());
4071 if (CFLinkCheckFunc->empty()) {
4072 CFLinkCheckFunc->setLinkage(llvm::GlobalValue::LinkOnceAnyLinkage);
4073 CFLinkCheckFunc->setVisibility(llvm::GlobalValue::HiddenVisibility);