Lines Matching +full:push +full:- +full:ci +full:- +full:container
1 //===------- CGObjCMac.cpp - Interface to Apple Objective-C Runtime -------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This provides Objective-C code generation targeting the Apple runtime.
11 //===----------------------------------------------------------------------===//
62 /// the all-integer/pointer case.
64 // Add the non-lazy-bind attribute, since objc_msgSend is likely to
89 /// floating-point stack; without a special entrypoint, the nil case
102 /// would be unbalanced. Only used on 64-bit X86.
178 /// ObjectPtrTy - LLVM type for object handles (typeof(id))
181 /// PtrObjectPtrTy - LLVM type for id *
184 /// SelectorPtrTy - LLVM type for selector handles (typeof(SEL))
188 /// ProtocolPtrTy - LLVM type for external protocol handles
206 // SuperCTy - clang type for struct objc_super.
208 // SuperPtrCTy - clang type for struct objc_super *.
211 /// SuperTy - LLVM type for struct objc_super.
213 /// SuperPtrTy - LLVM type for struct objc_super *.
216 /// PropertyTy - LLVM type for struct objc_property (struct _prop_t
220 /// PropertyListTy - LLVM type for struct objc_property_list
223 /// PropertyListPtrTy - LLVM type for struct objc_property_list*.
226 // MethodTy - LLVM type for struct objc_method.
229 /// CacheTy - LLVM type for struct objc_cache.
231 /// CachePtrTy - LLVM type for struct objc_cache *.
242 Ctx.getPointerDiffType()->getCanonicalTypeUnqualified(), Ctx.BoolTy};
258 Ctx.getPointerDiffType()->getCanonicalTypeUnqualified(),
286 Params.push_back(Ctx.getPointerDiffType()->getCanonicalTypeUnqualified());
363 /// GcReadWeakFn -- LLVM objc_read_weak (id *src) function.
372 /// GcAssignWeakFn -- LLVM objc_assign_weak function.
381 /// GcAssignGlobalFn -- LLVM objc_assign_global function.
390 /// GcAssignThreadLocalFn -- LLVM objc_assign_threadlocal function.
399 /// GcAssignIvarFn -- LLVM objc_assign_ivar function.
408 /// GcMemmoveCollectableFn -- LLVM objc_memmove_collectable function.
416 /// GcAssignStrongCastFn -- LLVM objc_assign_strongCast function.
425 /// ExceptionThrowFn - LLVM objc_exception_throw function.
434 /// ExceptionRethrowFn - LLVM objc_exception_rethrow function.
441 /// SyncEnterFn - LLVM object_sync_enter function.
450 /// SyncExitFn - LLVM object_sync_exit function.
494 /// ObjCTypesHelper - Helper class that encapsulates lazy
498 /// SymtabTy - LLVM type for struct objc_symtab.
500 /// SymtabPtrTy - LLVM type for struct objc_symtab *.
502 /// ModuleTy - LLVM type for struct objc_module.
505 /// ProtocolTy - LLVM type for struct objc_protocol.
507 /// ProtocolPtrTy - LLVM type for struct objc_protocol *.
509 /// ProtocolExtensionTy - LLVM type for struct
512 /// ProtocolExtensionTy - LLVM type for struct
515 /// MethodDescriptionTy - LLVM type for struct
518 /// MethodDescriptionListTy - LLVM type for struct
521 /// MethodDescriptionListPtrTy - LLVM type for struct
524 /// ProtocolListTy - LLVM type for struct objc_property_list.
526 /// ProtocolListPtrTy - LLVM type for struct objc_property_list*.
528 /// CategoryTy - LLVM type for struct objc_category.
530 /// ClassTy - LLVM type for struct objc_class.
532 /// ClassPtrTy - LLVM type for struct objc_class *.
534 /// ClassExtensionTy - LLVM type for struct objc_class_ext.
536 /// ClassExtensionPtrTy - LLVM type for struct objc_class_ext *.
538 // IvarTy - LLVM type for struct objc_ivar.
540 /// IvarListTy - LLVM type for struct objc_ivar_list.
542 /// IvarListPtrTy - LLVM type for struct objc_ivar_list *.
544 /// MethodListTy - LLVM type for struct objc_method_list.
546 /// MethodListPtrTy - LLVM type for struct objc_method_list *.
549 /// ExceptionDataTy - LLVM type for struct _objc_exception_data.
552 /// ExceptionTryEnterFn - LLVM objc_exception_try_enter function.
560 /// ExceptionTryExitFn - LLVM objc_exception_try_exit function.
568 /// ExceptionExtractFn - LLVM objc_exception_extract function.
576 /// ExceptionMatchFn - LLVM objc_exception_match function.
584 /// SetJmpFn - LLVM _setjmp function.
599 /// ObjCNonFragileABITypesHelper - will have all types needed by objective-c's
603 // MethodListnfABITy - LLVM for struct _method_list_t
606 // MethodListnfABIPtrTy - LLVM for struct _method_list_t*
615 // ProtocolListnfABITy - LLVM for struct _objc_protocol_list
618 // ProtocolListnfABIPtrTy - LLVM for struct _objc_protocol_list*
621 // ClassnfABITy - LLVM for struct _class_t
624 // ClassnfABIPtrTy - LLVM for struct _class_t*
627 // IvarnfABITy - LLVM for struct _ivar_t
630 // IvarListnfABITy - LLVM for struct _ivar_list_t
636 // ClassRonfABITy - LLVM for struct _class_ro_t
639 // ImpnfABITy - LLVM for id (*)(id, SEL, ...)
642 // CategorynfABITy - LLVM for struct _category_t
647 // MessageRefTy - LLVM for:
653 // MessageRefCTy - clang type for struct _message_ref_t
656 // MessageRefPtrTy - LLVM for struct _message_ref_t*
658 // MessageRefCPtrTy - clang type for struct _message_ref_t*
661 // SuperMessageRefTy - LLVM for:
668 // SuperMessageRefPtrTy - LLVM for struct _super_message_ref_t*
727 /// Loads from a classref. For Objective-C stub classes, this invokes the
731 // Add the non-lazy-bind attribute, since objc_loadClassref is likely to
749 cast<llvm::Function>(F.getCallee())->setLinkage(
786 /// a non-pointer. Note that this instruction is equal
793 /// subsequent word-size instructions do not begin at a multiple of
802 /// The next I+1 words are __strong pointers to Objective-C
809 /// The next I+1 words are __weak pointers to Objective-C
814 /// Objective-C objects or blocks.
818 /// as-yet-unspecified ownership semantics. If we add more
854 /// LazySymbols - Symbols to generate a lazy reference for. See
858 /// DefinedSymbols - External symbols which are defined by this
860 /// special linker symbols which ensure that Objective-C modules are
864 /// ClassNames - uniqued class names.
867 /// MethodVarNames - uniqued method variable names.
870 /// DefinedCategoryNames - list of category names in form Class_Category.
873 /// MethodVarTypes - uniqued method type signatures. We have to use
877 /// MethodDefinitions - map of methods which have been defined in
881 /// DirectMethodDefinitions - map of direct methods which have been defined in
885 /// PropertyNames - uniqued method variable names.
888 /// ClassReferences - uniqued class references.
891 /// SelectorReferences - uniqued selector references.
894 /// Protocols - Protocols for which an objc_protocol structure has
899 /// DefinedProtocols - Protocols which have actually been
903 /// DefinedClasses - List of defined classes.
906 /// ImplementedClasses - List of @implemented classes.
909 /// DefinedNonLazyClasses - List of defined "non-lazy" classes.
912 /// DefinedCategories - List of defined categories.
915 /// DefinedStubCategories - List of defined categories on class stubs.
918 /// DefinedNonLazyCategories - List of defined "non-lazy" categories.
922 /// int * but is actually an Obj-C class pointer.
930 /// GetMethodVarName - Return a unique constant for the given
935 /// GetMethodVarType - Return a unique constant for the given
943 /// GetPropertyName - Return a unique constant for the given
949 const Decl *Container);
951 /// GetClassName - Return a unique constant for the given selector's
958 /// BuildIvarLayout - Builds ivar layout bitmap for the class
961 /// \param hasMRCWeakIvars - Whether we are compiling in MRC and there
964 /// actually have any entries, because the ivar might be under-aligned.
1005 /// GetIvarLayoutName - Returns a unique constant for the given
1010 /// EmitPropertyList - Emit the given property list. The return
1013 const Decl *Container,
1018 /// EmitProtocolMethodTypes - Generate the array of extended method type
1024 /// GetProtocolRef - Return a reference to the internal protocol
1038 /// CreateMetadataVar - Create a global variable with internal
1039 /// linkage for use by the Objective-C runtime.
1045 /// \param Name - The variable name.
1046 /// \param Init - The variable initializer; this is also used to
1048 /// \param Section - The section the variable should go into, or empty.
1049 /// \param Align - The alignment for the variable, or 0.
1050 /// \param AddToUsed - Whether the variable should be added to
1079 /// EmitImageInfo - Emit the image info marker used to encode some module
1106 /// GetOrEmitProtocolRef - Get a forward reference to the protocol
1174 for (auto *MD : PD->methods()) {
1175 size_t index = (2 * size_t(MD->isOptional()))
1176 + (size_t(MD->isClassMethod()));
1196 result.push_back(self->GetMethodVarType(MD, true));
1206 return self->emitMethodList(PD->getObjCRuntimeNameAsString(),
1219 /// EmitModuleInfo - Another marker encoding module level
1223 /// EmitModuleSymols - Emit module symbols, the list of defined
1227 /// FinishModule - Write out global data structures at the end of
1231 /// EmitClassExtension - Generate the class extension structure used
1239 /// EmitClassRef - Return a Value*, of type ObjCTypes.ClassPtrTy,
1249 /// EmitSuperClassRef - Emits reference to class's main metadata class.
1252 /// EmitIvarList - Emit the ivar list for the given
1260 /// EmitMetaClass - Emit a forward reference to the class structure
1265 /// EmitMetaClass - Emit a class structure for the metaclass of the
1277 /// EmitMethodList - Emit the method list for the given
1282 /// GetOrEmitProtocol - Get the protocol object for the given
1287 /// GetOrEmitProtocolRef - Get a forward reference to the protocol
1293 /// EmitProtocolExtension - Generate the protocol extension
1301 /// EmitProtocolList - Generate the list of referenced
1307 /// EmitSelector - Return a Value*, of type ObjCTypes.SelectorPtrTy,
1405 /// SuperClassReferences - uniqued super class references.
1408 /// MetaClassReferences - uniqued meta class references.
1411 /// EHTypeReferences - uniqued class ehtype references.
1414 /// VTableDispatchMethods - List of methods for which we generate
1415 /// vtable-based message dispatch.
1418 /// DefinedMetaClasses - List of defined meta-classes.
1421 /// isVTableDispatchedSelector - Returns true if SEL is a
1422 /// vtable-based selector.
1425 /// FinishNonFragileABIModule - Write out global data structures at the end of
1429 /// AddModuleClassList - Add the given list of class pointers to the
1431 void AddModuleClassList(ArrayRef<llvm::GlobalValue *> Container,
1438 llvm::GlobalVariable *BuildClassObject(const ObjCInterfaceDecl *CI,
1454 /// EmitIvarList - Emit the ivar list for the given
1465 /// GetOrEmitProtocol - Get the protocol object for the given
1470 /// GetOrEmitProtocolRef - Get a forward reference to the protocol
1476 /// EmitProtocolList - Generate the list of referenced
1492 /// GetClassGlobal - Return the global variable for the Objective-C
1507 /// EmitClassRef - Return a Value*, of type ObjCTypes.ClassPtrTy,
1518 /// EmitSuperClassRef - Return a Value*, of type ObjCTypes.ClassPtrTy,
1523 /// EmitMetaClassRef - Return a Value * of the address of _class_t
1524 /// meta-data
1528 /// ObjCIvarOffsetVariable - Returns the ivar offset variable for
1535 /// EmitSelector - Return a Value*, of type ObjCTypes.SelectorPtrTy,
1540 /// GetInterfaceEHType - Get the cached ehtype for the given Objective-C
1564 /// ImplementationIsNonLazy - Check whether the given category or
1565 /// class implementation is "non-lazy".
1586 if (MD->isInstanceMethod() && !MD->isDirectMethod())
1587 if (const ObjCInterfaceDecl *ID = MD->getClassInterface())
1588 return IV->getContainingInterface()->isSuperClassOf(ID);
1595 for (; ID; ID = ID->getSuperClass()) {
1598 if (ID->getIdentifier()->getName() == "NSObject")
1603 if (!ID->getImplementation())
1644 { return EmitSelector(CGF, Method->getSelector()); }
1718 /// A helper class for performing the null-initialization of a return
1724 /// Perform a null-check of the given receiver.
1726 // Make blocks for the null-receiver and call edges.
1727 NullBB = CGF.createBasicBlock("msgSend.null-receiver");
1731 // null-receiver block. There's no point in trying to avoid it:
1733 // we shouldn't have done this null-check in the first place.
1741 /// Complete the null-return operation. It is valid to call this
1749 // If we never had to do a null-check, just use the raw result.
1763 // Okay, start emitting the null-receiver block.
1775 if (result.isScalar() && resultType->isVoidType()) {
1776 // No jumps required if the message-send was noreturn.
1783 // Derive the null-initialization value.
1792 llvm::PHINode *phi = CGF.Builder.CreatePHI(null->getType(), 2);
1793 phi->addIncoming(result.getScalarVal(), callBB);
1794 phi->addIncoming(null, NullBB);
1800 // cases where the ABI has us returning (1) non-agg values in
1803 assert(result.isAggregate() && "null init of non-aggregate result?");
1815 llvm::Type *scalarTy = callResult.first->getType();
1820 real->addIncoming(callResult.first, callBB);
1821 real->addIncoming(scalarZero, NullBB);
1823 imag->addIncoming(callResult.second, callBB);
1824 imag->addIncoming(scalarZero, NullBB);
1833 /// getConstantGEP() - Help routine to construct simple GEPs.
1841 return llvm::ConstantExpr::getGetElementPtr(C->getValueType(), C, Idxs);
1844 /// hasObjCExceptionAttribute - Return true if this class or any super
1848 if (OID->hasAttr<ObjCExceptionAttr>())
1850 if (const ObjCInterfaceDecl *Super = OID->getSuperClass())
1873 GV->setSection(SectionName);
1885 /// GetClass - Return a reference to the class for the given interface
1892 /// GetSelector - Return the pointer to the unique'd string for this selector.
1901 return EmitSelector(CGF, Method->getSelector());
1905 if (T->isObjCIdType() ||
1906 T->isObjCQualifiedIdType()) {
1910 if (T->isObjCClassType() ||
1911 T->isObjCQualifiedClassType()) {
1915 if (T->isObjCObjectPointerType())
1950 StringRef String = Literal->getString();
1991 C, C->getValueType(), CharUnits::fromQuantity(C->getAlignment()));
2016 auto *GV = new llvm::GlobalVariable(CGM.getModule(), C->getType(), isConstant,
2018 GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
2021 GV->setAlignment(llvm::Align(1));
2036 GV->setSection(CGM.getLangOpts().ObjCRuntime.isNonFragile()
2041 return ConstantAddress(GV, GV->getValueType(), Alignment);
2082 Target = EmitClassRef(CGF, Class->getSuperClass());
2095 Target = EmitClassRef(CGF, Class->getSuperClass());
2147 if (!Method || !Method->isDirectMethod())
2155 assert(CGM.getContext().getCanonicalType(Method->getReturnType()) ==
2166 if (Method && Method->isDirectMethod()) {
2168 Fn = GenerateDirectMethod(Method, Method->getClassInterface());
2200 // Emit a null-check if there's a consumed argument other than the receiver.
2201 if (!RequiresNullCheck && Method && Method->hasParamDestroyedInCallee())
2222 if (Method && Method->hasAttr<NoReturnAttr>() && !ReceiverCanBeNull) {
2223 CallSite->setDoesNotReturn();
2255 if (FQT->isObjCObjectPointerType() || FQT->isBlockPointerType())
2260 if (const PointerType *PT = FQT->getAs<PointerType>())
2261 return GetGCAttrTypeForType(Ctx, PT->getPointeeType(), /*pointee*/ true);
2294 /// Whether the offsets in IvarsInfo might be out-of-order.
2374 for (const auto &CI : blockDecl->captures()) {
2375 const VarDecl *variable = CI.getVariable();
2376 QualType type = variable->getType();
2386 // adding them out-of-order, make sure we sort later.
2392 if (CI.isByRef()) {
2397 assert(!type->isArrayType() && "array variable should not be caught");
2398 if (const RecordType *record = type->getAs<RecordType>()) {
2413 /// getBlockCaptureLifetime - This routine returns life time of the captured
2414 /// block variable for the purpose of block layout meta-data generation. FQT is
2426 // In MRC, retainable pointers are owned by non-__block variables.
2427 if (FQT->isObjCObjectPointerType() || FQT->isBlockPointerType())
2461 bool IsUnion = (RD && RD->isUnion());
2481 if (!Field->getIdentifier() || Field->isBitField()) {
2488 QualType FQT = Field->getType();
2489 if (FQT->isRecordType() || FQT->isUnionType()) {
2490 if (FQT->isUnionType())
2493 BuildRCBlockVarRecordLayout(FQT->castAs<RecordType>(),
2500 uint64_t ElCount = CArray->getZExtSize();
2502 FQT = CArray->getElementType();
2505 ElCount *= CArray->getZExtSize();
2506 FQT = CArray->getElementType();
2508 if (FQT->isRecordType() && ElCount) {
2509 int OldIndex = RunSkipBlockVars.size() - 1;
2510 auto *RT = FQT->castAs<RecordType>();
2516 for (int FirstIndex = RunSkipBlockVars.size() - 1 ;ElIx < ElCount; ElIx++) {
2527 CharUnits FieldSize = CGM.getContext().getTypeSizeInChars(Field->getType());
2544 if (LastFieldBitfieldOrUnnamed->isBitField()) {
2546 uint64_t BitFieldSize = LastFieldBitfieldOrUnnamed->getBitWidthValue();
2552 getBlockCaptureLifetime(LastFieldBitfieldOrUnnamed->getType(),
2557 assert(!LastFieldBitfieldOrUnnamed->getIdentifier() &&"Expected unnamed");
2560 = CGM.getContext().getTypeSizeInChars(LastFieldBitfieldOrUnnamed->getType());
2562 getBlockCaptureLifetime(LastFieldBitfieldOrUnnamed->getType(),
2571 getBlockCaptureLifetime(MaxField->getType(), ByrefLayout),
2580 const RecordDecl *RD = RT->getDecl();
2581 SmallVector<const FieldDecl*, 16> Fields(RD->fields());
2589 /// InlineLayoutInstruction - This routine produce an inline instruction for the
2723 end_byte_pos - start_byte_pos + RunSkipBlockVars[j-1].block_var_size;
2726 RunSkipBlockVars[j].block_var_bytepos -
2727 RunSkipBlockVars[j-1].block_var_bytepos - RunSkipBlockVars[j-1].block_var_size;
2733 size_in_bytes -= residue_in_bytes;
2743 size_in_words -= 16;
2748 unsigned char inst = (opcode << 4) | (size_in_words-1);
2753 (BLOCK_LAYOUT_NON_OBJECT_BYTES << 4) | (residue_in_bytes.getQuantity()-1);
2829 if (i < e-1)
2855 // happens when the block is non-escaping).
2902 for (const auto &CI : blockDecl->captures()) {
2903 const VarDecl *variable = CI.getVariable();
2904 QualType type = variable->getType();
2912 CharUnits::fromQuantity(layout->getElementOffset(capture.getIndex()));
2914 assert(!type->isArrayType() && "array variable should not be caught");
2915 if (!CI.isByRef())
2916 if (const RecordType *record = type->getAs<RecordType>()) {
2921 if (CI.isByRef())
2925 UpdateRunSkipBlockVars(CI.isByRef(), getBlockCaptureLifetime(type, false),
2946 assert(!T->isArrayType() && "__block array variable should not be caught");
2950 if (const RecordType *record = T->getAs<RecordType>()) {
2973 DefinedProtocols.insert(PD->getIdentifier());
2978 if (Protocols.count(PD->getIdentifier()))
2983 if (DefinedProtocols.count(PD->getIdentifier()))
2997 ID->getObjCRuntimeNameAsString()))
3005 call->setDoesNotThrow();
3010 // Objective-C 1.0 extensions
3022 llvm::GlobalVariable *Entry = Protocols[PD->getIdentifier()];
3025 if (Entry && Entry->hasInitializer())
3029 if (const ObjCProtocolDecl *Def = PD->getDefinition())
3042 values.add(GetClassName(PD->getObjCRuntimeNameAsString()));
3043 values.add(EmitProtocolList("OBJC_PROTOCOL_REFS_" + PD->getName(),
3044 PD->protocol_begin(), PD->protocol_end()));
3052 assert(Entry->hasPrivateLinkage());
3055 Entry = values.finishAndCreateGlobal("OBJC_PROTOCOL_" + PD->getName(),
3059 Entry->setSection("__OBJC,__protocol,regular,no_dead_strip");
3061 Protocols[PD->getIdentifier()] = Entry;
3069 llvm::GlobalVariable *&Entry = Protocols[PD->getIdentifier()];
3077 nullptr, "OBJC_PROTOCOL_" + PD->getName());
3078 Entry->setSection("__OBJC,__protocol,regular,no_dead_strip");
3080 Entry->setAlignment(llvm::Align(4));
3107 EmitProtocolMethodTypes("OBJC_PROTOCOL_METHOD_TYPES_" + PD->getName(),
3112 EmitPropertyList("OBJC_$_PROP_PROTO_LIST_" + PD->getName(), nullptr, PD,
3115 EmitPropertyList("OBJC_$_CLASS_PROP_PROTO_LIST_" + PD->getName(), nullptr,
3119 if (optInstanceMethods->isNullValue() &&
3120 optClassMethods->isNullValue() &&
3121 extendedMethodTypes->isNullValue() &&
3122 instanceProperties->isNullValue() &&
3123 classProperties->isNullValue()) {
3140 return CreateMetadataVar("_OBJC_PROTOCOLEXT_" + PD->getName(), values,
3195 for (const auto *PD : Proto->properties()) {
3196 if (IsClassProperty != PD->isClassProperty())
3198 if (!PropertySet.insert(PD->getIdentifier()).second)
3203 for (const auto *P : Proto->protocols())
3220 const Decl *Container,
3237 for (const ObjCCategoryDecl *ClassExt : OID->known_extensions())
3238 for (auto *PD : ClassExt->properties()) {
3239 if (IsClassProperty != PD->isClassProperty())
3241 if (PD->isDirectProperty())
3243 PropertySet.insert(PD->getIdentifier());
3247 for (const auto *PD : OCD->properties()) {
3248 if (IsClassProperty != PD->isClassProperty())
3252 if (!PropertySet.insert(PD->getIdentifier()).second)
3254 if (PD->isDirectProperty())
3260 for (const auto *P : OID->all_referenced_protocols())
3264 for (const auto *P : CD->protocols())
3282 property.add(GetPropertyName(PD->getIdentifier()));
3283 property.add(GetPropertyTypeString(PD, Container));
3338 const ObjCInterfaceDecl *Interface = OCD->getClassInterface();
3340 Interface->FindCategoryDeclaration(OCD->getIdentifier());
3343 llvm::raw_svector_ostream(ExtName) << Interface->getName() << '_'
3344 << OCD->getName();
3355 for (const auto *MD : OCD->methods()) {
3356 if (!MD->isDirectMethod())
3357 Methods[unsigned(MD->isClassMethod())].push_back(MD);
3360 Values.add(GetClassName(OCD->getName()));
3361 Values.add(GetClassName(Interface->getObjCRuntimeNameAsString()));
3362 LazySymbols.insert(Interface->getIdentifier());
3371 Category->protocol_begin(), Category->protocol_end()));
3399 /// Apparently: is not a meta-class.
3402 /// Is a meta-class.
3405 /// Has a non-trivial constructor or destructor.
3420 /// Is a meta-class.
3426 /// Has a non-trivial constructor or destructor.
3435 /// (Obsolete) ARC-specific: this class has a .release_ivars method
3441 /// Class has non-trivial destructors, but zero-initialization is okay.
3454 if (auto recType = type->getAs<RecordType>()) {
3455 for (auto *field : recType->getDecl()->fields()) {
3456 if (hasWeakMember(field->getType()))
3473 ID->getClassInterface()->all_declared_ivar_begin();
3474 ivar; ivar = ivar->getNextIvar()) {
3475 if (hasWeakMember(ivar->getType()))
3494 // Objective-C 1.0 extensions (<rdr://4585769>)
3503 &CGM.getContext().Idents.get(ID->getObjCRuntimeNameAsString());
3506 std::string ClassName = ID->getNameAsString();
3509 const_cast<ObjCInterfaceDecl*>(ID->getClassInterface());
3511 EmitProtocolList("OBJC_CLASS_PROTOCOLS_" + ID->getName(),
3512 Interface->all_referenced_protocol_begin(),
3513 Interface->all_referenced_protocol_end());
3515 if (ID->hasNonZeroConstructors() || ID->hasDestructors())
3528 // FIXME: Set CXX-structors flag.
3529 if (ID->getClassInterface()->getVisibility() == HiddenVisibility)
3538 for (const auto *MD : ID->methods()) {
3539 if (!MD->isDirectMethod())
3540 Methods[unsigned(MD->isClassMethod())].push_back(MD);
3543 for (const auto *PID : ID->property_impls()) {
3544 if (PID->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize) {
3545 if (PID->getPropertyDecl()->isDirectProperty())
3547 if (ObjCMethodDecl *MD = PID->getGetterMethodDecl())
3550 if (ObjCMethodDecl *MD = PID->getSetterMethodDecl())
3559 if (ObjCInterfaceDecl *Super = Interface->getSuperClass()) {
3561 LazySymbols.insert(Super->getIdentifier());
3563 values.add(GetClassName(Super->getObjCRuntimeNameAsString()));
3567 values.add(GetClassName(ID->getObjCRuntimeNameAsString()));
3573 values.add(emitMethodList(ID->getName(), MethodListType::InstanceMethods,
3588 assert(GV->getValueType() == ObjCTypes.ClassTy &&
3591 GV->setSection(Section);
3592 GV->setAlignment(CGM.getPointerAlign().getAsAlign());
3608 if (ID->getClassInterface()->getVisibility() == HiddenVisibility)
3614 const ObjCInterfaceDecl *Root = ID->getClassInterface();
3615 while (const ObjCInterfaceDecl *Super = Root->getSuperClass())
3617 values.add(GetClassName(Root->getObjCRuntimeNameAsString()));
3621 if (ObjCInterfaceDecl *Super = ID->getClassInterface()->getSuperClass()) {
3622 values.add(GetClassName(Super->getObjCRuntimeNameAsString()));
3626 values.add(GetClassName(ID->getObjCRuntimeNameAsString()));
3632 values.add(emitMethodList(ID->getName(), MethodListType::ClassMethods,
3644 Name += ID->getName();
3649 assert(GV->getValueType() == ObjCTypes.ClassTy &&
3657 GV->setSection("__OBJC,__meta_class,regular,no_dead_strip");
3664 std::string Name = "OBJC_METACLASS_" + ID->getNameAsString();
3680 assert(GV->getValueType() == ObjCTypes.ClassTy &&
3686 std::string Name = "OBJC_CLASS_" + ID->getNameAsString();
3694 assert(GV->getValueType() == ObjCTypes.ClassTy &&
3701 data that doesn't fit in the normal fragile-ABI class structure, and
3727 + ID->getName(),
3728 ID, ID->getClassInterface(), ObjCTypes, isMetaclass);
3731 if (layout->isNullValue() && propertyList->isNullValue()) {
3744 return CreateMetadataVar("OBJC_CLASSEXT_" + ID->getName(), values,
3771 const ObjCInterfaceDecl *OID = ID->getClassInterface();
3778 for (const ObjCIvarDecl *IVD = OID->all_declared_ivar_begin();
3779 IVD; IVD = IVD->getNextIvar()) {
3780 // Ignore unnamed bit-fields.
3781 if (!IVD->getDeclName())
3785 ivar.add(GetMethodVarName(IVD->getIdentifier()));
3803 GV = CreateMetadataVar("OBJC_INSTANCE_VARIABLES_" + ID->getName(), ivarList,
3818 description.add(GetMethodVarName(MD->getSelector()));
3836 method.add(GetMethodVarName(MD->getSelector()));
3933 if (!MD->isDirectMethod())
3947 if (OMD->isDirectMethod()) {
3968 auto *COMD = OMD->getCanonicalDecl();
3973 // Objective-C allows for the declaration and implementation types
3982 if (!OMD->getBody() || COMD->getReturnType() == OMD->getReturnType())
3983 return I->second;
3984 OldFn = I->second;
3994 Fn->takeName(OldFn);
3995 OldFn->replaceAllUsesWith(Fn);
3996 OldFn->eraseFromParent();
3999 I->second = Fn;
4016 auto selfAddr = CGF.GetAddrOfLocalVar(OMD->getSelfDecl());
4032 if (OMD->isClassMethod()) {
4042 // already initialized; for example, it might be an ordinary Objective-C
4066 auto selfTy = cast<llvm::PointerType>(selfValue->getType());
4076 auto retTy = OMD->getReturnType();
4078 if (!retTy->isVoidType()) {
4090 if (OMD->getCmdDecl()->isUsed()) {
4093 CGF.EmitVarDecl(*OMD->getCmdDecl());
4095 CGF.GetAddrOfLocalVar(OMD->getCmdDecl()));
4109 GV->setSection(Section);
4120 llvm::Type *Ty = Init->getType();
4126 GV->setSection(Section);
4127 GV->setAlignment(Align.getAsAlign());
4170 new llvm::GlobalVariable(CGM.getModule(), Value->getType(),
4174 GV->setSection(Section);
4175 GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
4176 GV->setAlignment(CharUnits::One().getAsAlign());
4272 CGF.EmitStmt(FinallyStmt->getFinallyBody());
4312 /// Create the fragile-ABI read and write hazards based on the current
4324 I = CGF.CurFn->begin(), E = CGF.CurFn->end(); I != E; ++I)
4329 // Create a read hazard for the allocas. This inhibits dead-store
4365 Call->addParamAttr(Pair.index(), llvm::Attribute::get(
4367 cast<llvm::AllocaInst>(Pair.value())->getAllocatedType()));
4373 call->setDoesNotThrow();
4374 call->setCallingConv(CGF.getRuntimeCC());
4376 call->addParamAttr(Pair.index(), llvm::Attribute::get(
4378 cast<llvm::AllocaInst>(Pair.value())->getAllocatedType()));
4390 FI = CGF.CurFn->begin(), FE = CGF.CurFn->end(); FI != FE; ++FI) {
4399 // Ignore instructions that aren't non-intrinsic calls.
4436 llvm::BasicBlock &Entry = CGF.CurFn->getEntryBlock();
4446 tys[i] = Locals[i]->getType();
4452 Objective-C setjmp-longjmp (sjlj) Exception Handling
4453 --
4456 - a pointer to the exception that was caught
4457 - a pointer to the previous exception data buffer
4458 - two pointers of reserved storage
4460 of the stack kept in thread-local storage.
4472 There's no reason an implementation couldn't use a light-weight
4473 setjmp here --- something like __builtin_setjmp, but API-compatible
4481 inhibit optimizing locals across the setjmp->catch edge.
4483 The basic framework for a @try-catch-finally is as follows:
4502 ... jump-through-finally to finally_rethrow ...
4507 ... jump-through-finally to finally_rethrow ...
4510 ... jump-through-finally to finally_end ...
4532 - If there are no catch blocks, then we avoid emitting the second
4535 - If there is a catch-all catch block (i.e. @catch(...) or @catch(id
4538 - FIXME: If there is no @finally block we can do a few more
4541 Rethrows and Jumps-Through-Finally
4542 --
4544 '@throw;' is supported by pushing the currently-caught exception
4548 normal cleanup. We do not register an EH cleanup; fragile-ABI ObjC
4562 // A destination for the fall-through edges of the catch handlers to
4584 SyncArgSlot = CGF.CreateTempAlloca(SyncArg->getType(),
4603 // - no catches match and we're branching through the cleanup
4605 // - a catch matched and we're falling out of the catch handler.
4606 // The setjmp-safety rule here is that we should always store to this
4617 // Push a normal cleanup to leave the try scope.
4625 // - Call objc_exception_try_enter to push ExceptionData on top of
4630 // - Call setjmp on the exception data buffer.
4638 SetJmpResult->setCanReturnTwice();
4659 // Don't optimize loads of the in-scope locals across this point.
4665 // Tell the cleanup not to re-pop the exit.
4677 // Push the exception to rethrow onto the EH value stack for the
4683 bool HasFinally = (AtTryStmt->getFinallyStmt() != nullptr);
4688 // Save the currently-propagating exception before
4690 PropagatingExnVar = CGF.CreateTempAlloca(Caught->getType(),
4703 SetJmpResult->setCanReturnTwice();
4721 for (const ObjCAtCatchStmt *CatchStmt : AtTryStmt->catch_stmts()) {
4722 const VarDecl *CatchParam = CatchStmt->getCatchParamDecl();
4729 OPT = CatchParam->getType()->getAs<ObjCObjectPointerType>();
4735 if (OPT && (OPT->isObjCIdType() || OPT->isObjCQualifiedIdType()))
4739 // If this is a catch-all, we don't need to test anything.
4751 CGF.EmitStmt(CatchStmt->getCatchBody());
4760 assert(OPT && "Unexpected non-object pointer type in @catch");
4761 const ObjCObjectType *ObjTy = OPT->getObjectType();
4764 ObjCInterfaceDecl *IDecl = ObjTy->getInterface();
4765 assert(IDecl && "Catch parameter must have Objective-C type!");
4794 CGF.ConvertType(CatchParam->getType()));
4797 CGF.EmitStmt(CatchStmt->getCatchBody());
4811 if (Caught->use_empty())
4812 Caught->eraseFromParent();
4822 // unnecessary because there's no local-accessing code between
4827 // propagating-exception slot.
4854 // If we have a propagating-exception variable, check it.
4890 ->setDoesNotReturn();
4898 /// EmitObjCWeakRead - Code gen for loading value of a __weak
4913 /// EmitObjCWeakAssign - Code gen for assigning to a __weak object.
4918 llvm::Type * SrcTy = src->getType();
4934 /// EmitObjCGlobalAssign - Code gen for assigning to a __strong object.
4940 llvm::Type * SrcTy = src->getType();
4960 /// EmitObjCIvarAssign - Code gen for assigning to a __strong object.
4966 assert(ivarOffset && "EmitObjCIvarAssign - ivarOffset is NULL");
4967 llvm::Type * SrcTy = src->getType();
4982 /// EmitObjCStrongCastAssign - Code gen for assigning to a __strong cast object.
4987 llvm::Type * SrcTy = src->getType();
5011 /// EmitObjCValueForIvar - Code Gen for ivar reference.
5019 ObjectTy->castAs<ObjCObjectType>()->getInterface();
5057 "Objective-C support is unimplemented for object file format");
5063 /// EmitImageInfo - Emit the image info marker used to encode some module
5092 // Generate module-level named metadata to convey this information to the
5093 // linker and code-gen.
5097 Mod.addModuleFlag(llvm::Module::Error, "Objective-C Version", ObjCABI);
5098 Mod.addModuleFlag(llvm::Module::Error, "Objective-C Image Info Version",
5100 Mod.addModuleFlag(llvm::Module::Error, "Objective-C Image Info Section",
5105 // Non-GC overrides those files which specify GC.
5107 "Objective-C Garbage Collection",
5112 "Objective-C Garbage Collection",
5118 Mod.addModuleFlag(llvm::Module::Error, "Objective-C GC Only",
5123 llvm::MDString::get(VMContext, "Objective-C Garbage Collection"),
5126 Mod.addModuleFlag(llvm::Module::Require, "Objective-C GC Only",
5133 Mod.addModuleFlag(llvm::Module::Error, "Objective-C Is Simulated",
5137 Mod.addModuleFlag(llvm::Module::Error, "Objective-C Class Properties",
5187 if (ObjCImplementationDecl *IMP = ID->getImplementation())
5189 if (ID->isWeakImported() && !IMP->isWeakImported())
5190 DefinedClasses[i]->setLinkage(llvm::GlobalVariable::ExternalLinkage);
5213 CreateMetadataVar("OBJC_CLASS_REFERENCES_", GetClassName(II->getName()),
5218 return CGF.Builder.CreateAlignedLoad(Entry->getValueType(), Entry,
5225 // use the Objective-C runtime to get the class.
5226 if (ID->hasAttr<ObjCRuntimeVisibleAttr>())
5230 &CGM.getContext().Idents.get(ID->getObjCRuntimeNameAsString());
5251 Entry->setExternallyInitialized(true);
5268 /// GetIvarLayoutName - Returns a unique constant for the given
5277 const RecordDecl *RD = RT->getDecl();
5281 if (RD->isUnion())
5285 visitAggregate(RD->field_begin(), RD->field_end(), offset,
5286 [&](const FieldDecl *field) -> CharUnits {
5289 auto offsetInBits = recLayout->getFieldOffset(field->getFieldIndex());
5302 if (field->isBitField()) {
5316 QualType fieldType = field->getType();
5322 fieldType = arrayType->getElementType();
5326 numElts *= arrayType->getZExtSize();
5327 fieldType = arrayType->getElementType();
5330 assert(!fieldType->isArrayType() && "ivar of non-constant array type?");
5332 // If we ended up with a zero-sized array, we've done what we can do within
5337 if (auto recType = fieldType->getAs<RecordType>()) {
5343 auto numEltEntries = IvarsInfo.size() - oldEnd;
5372 /// buildBitmap - This routine does the horsework of taking the offsets of
5406 unsigned claimed = std::min(MaxNibble - lastSkip, numWords);
5407 numWords -= claimed;
5415 numWords -= MaxNibble;
5431 unsigned claimed = std::min(MaxNibble - lastScan, numWords);
5432 numWords -= claimed;
5440 numWords -= MaxNibble;
5453 CharUnits beginOfScan = request.Offset - InstanceBegin;
5461 // isn't the true start of the ivars, because in the fragile-ARC case
5475 skip(beginOfScanInWords - endOfLastScanInWords);
5487 scan(endOfScanInWords - beginOfScanInWords);
5496 // or necessary for the ARC-style layout strings.
5499 (InstanceEnd - InstanceBegin + WordSize - CharUnits::One()) / WordSize;
5501 skip(lastOffsetInWords - endOfLastScanInWords);
5513 /// BuildIvarLayout - Builds ivar layout bitmap for the class
5517 /// Each byte is divided up in two nibbles (4-bit each). Left nibble is count
5522 /// - id, Class
5523 /// - object *
5524 /// - __strong anything
5527 /// - __weak anything
5541 const ObjCInterfaceDecl *OI = OMD->getClassInterface();
5545 // inaccurately in the non-fragile ABI; the runtime knows how to fix this
5548 // ARC layout strings only include the class's ivars. In non-fragile
5556 for (const ObjCIvarDecl *IVD = OI->all_declared_ivar_begin();
5557 IVD; IVD = IVD->getNextIvar())
5583 [&](const ObjCIvarDecl *ivar) -> CharUnits {
5596 OMD->getClassInterface()->getName().str().c_str());
5617 CGM.getContext().getObjCEncodingForType(Field->getType(), TypeStr, Field);
5640 Entry = CreateCStringLiteral(Ident->getName(), ObjCLabelType::PropertyName);
5648 const Decl *Container) {
5650 CGM.getContext().getObjCEncodingForPropertyDecl(PD, Container);
5661 if (global->hasInitializer())
5667 values.add(GetClassName(entry.first->getName()));
5689 OS << "\t.objc_class_name_" << Sym->getName() << "=0\n"
5690 << "\t.globl .objc_class_name_" << Sym->getName() << "\n";
5692 OS << "\t.lazy_reference .objc_class_name_" << Sym->getName() << "\n";
5752 RD->addDecl(FieldDecl::Create(Ctx, RD, SourceLocation(), SourceLocation(),
5755 RD->addDecl(FieldDecl::Create(Ctx, RD, SourceLocation(), SourceLocation(),
5758 RD->completeDefinition();
5946 // specific. 18 is what's used on 32-bit X86.
6049 // ImpnfABITy - LLVM for id (*)(id, SEL, ...)
6089 // MessageRefTy - LLVM for:
6099 RD->addDecl(FieldDecl::Create(Ctx, RD, SourceLocation(), SourceLocation(),
6102 RD->addDecl(FieldDecl::Create(Ctx, RD, SourceLocation(), SourceLocation(),
6105 RD->completeDefinition();
6111 // MessageRefPtrTy - LLVM for struct _message_ref_t*
6114 // SuperMessageRefTy - LLVM for:
6122 // SuperMessageRefPtrTy - LLVM for struct _super_message_ref_t*
6144 ArrayRef<llvm::GlobalValue *> Container, StringRef SymbolName,
6146 unsigned NumClasses = Container.size();
6153 Symbols[i] = Container[i];
6166 CGM.getModule(), Init->getType(), false,
6168 GV->setAlignment(CGM.getDataLayout().getABITypeAlign(Init->getType()));
6169 GV->setSection(SectionName);
6182 if (ObjCImplementationDecl *IMP = ID->getImplementation())
6184 if (ID->isWeakImported() && !IMP->isWeakImported()) {
6185 DefinedClasses[i]->setLinkage(llvm::GlobalVariable::ExternalLinkage);
6186 DefinedMetaClasses[i]->setLinkage(llvm::GlobalVariable::ExternalLinkage);
6213 /// isVTableDispatchedSelector - Returns true if SEL is not in the list of
6215 /// except for the 19 selectors in the list, we generate 32bit-style
6218 // At various points we've experimented with using vtable-based
6229 // If so, see whether this selector is in the white-list of things which must
6239 // These are vtable-based if GC is disabled.
6255 // These are vtable-based if GC is enabled.
6274 /// BuildClassRoTInitializer - generate meta-data for:
6294 std::string ClassName = std::string(ID->getObjCRuntimeNameAsString());
6314 values.add(GetClassName(ID->getObjCRuntimeNameAsString()));
6319 for (const auto *MD : ID->class_methods())
6320 if (!MD->isDirectMethod())
6323 for (const auto *MD : ID->instance_methods())
6324 if (!MD->isDirectMethod())
6328 values.add(emitMethodList(ID->getObjCRuntimeNameAsString(),
6334 const ObjCInterfaceDecl *OID = ID->getClassInterface();
6337 + OID->getObjCRuntimeNameAsString(),
6338 OID->all_referenced_protocol_begin(),
6339 OID->all_referenced_protocol_end()));
6345 "_OBJC_$_CLASS_PROP_LIST_" + ID->getObjCRuntimeNameAsString(),
6346 ID, ID->getClassInterface(), ObjCTypes, true));
6351 "_OBJC_$_PROP_LIST_" + ID->getObjCRuntimeNameAsString(),
6352 ID, ID->getClassInterface(), ObjCTypes, false));
6375 CGObjCNonFragileABIMac::BuildClassObject(const ObjCInterfaceDecl *CI,
6394 cast<llvm::GlobalVariable>(GetClassGlobal(CI, isMetaclass, ForDefinition));
6398 GV->setSection("__DATA, __objc_data");
6399 GV->setAlignment(CGM.getDataLayout().getABITypeAlign(ObjCTypes.ClassnfABITy));
6402 GV->setVisibility(llvm::GlobalValue::HiddenVisibility);
6408 return OD->getClassMethod(GetNullarySelector("load")) != nullptr ||
6409 OD->getClassInterface()->hasAttr<ObjCNonLazyClassAttr>() ||
6410 OD->hasAttr<ObjCNonLazyClassAttr>();
6436 for (const auto *Result : DC->lookup(&II))
6442 if (VD->hasAttr<DLLExportAttr>())
6444 if (VD->hasAttr<DLLImportAttr>())
6456 ObjCEmptyCacheVar->setDLLStorageClass(getStorage(CGM, "_objc_empty_cache"));
6477 const auto *CI = ID->getClassInterface();
6478 assert(CI && "CGObjCNonFragileABIMac::GenerateClass - class is 0");
6482 ? !CI->hasAttr<DLLExportAttr>()
6483 : CI->getVisibility() == HiddenVisibility;
6489 if (ID->hasNonZeroConstructors() || ID->hasDestructors()) {
6491 if (!ID->hasNonZeroConstructors())
6495 if (!CI->getSuperClass()) {
6499 SuperClassGV = GetClassGlobal(CI, /*metaclass*/ false, NotForDefinition);
6500 IsAGV = GetClassGlobal(CI, /*metaclass*/ true, NotForDefinition);
6503 const ObjCInterfaceDecl *Root = ID->getClassInterface();
6504 while (const ObjCInterfaceDecl *Super = Root->getSuperClass())
6507 const auto *Super = CI->getSuperClass();
6516 BuildClassObject(CI, /*metaclass*/ true,
6518 CGM.setGVProperties(MetaTClass, CI);
6526 if (ID->hasNonZeroConstructors() || ID->hasDestructors()) {
6531 // anything except zero-initialization during construction. This
6533 // also imagine there being C++ types with non-trivial default
6535 if (!ID->hasNonZeroConstructors())
6539 if (hasObjCExceptionAttribute(CGM.getContext(), CI))
6542 if (!CI->getSuperClass()) {
6547 const auto *Super = CI->getSuperClass();
6556 BuildClassObject(CI, /*metaclass*/ false,
6558 CGM.setGVProperties(ClassMD, CI);
6560 ImplementedClasses.push_back(CI);
6562 // Determine if this class is also "non-lazy".
6568 (void) GetInterfaceEHType(CI, ForDefinition);
6573 /// GenerateProtocolRef - This routine is called to generate code for
6579 /// which will hold address of the protocol meta-data.
6585 // of protocol's meta-data (not a reference to it!)
6586 assert(!PD->isNonRuntimeProtocol() &&
6591 ProtocolName += PD->getObjCRuntimeNameAsString();
6597 return CGF.Builder.CreateAlignedLoad(PTGV->getValueType(), PTGV, Align);
6598 PTGV = new llvm::GlobalVariable(CGM.getModule(), Init->getType(), false,
6601 PTGV->setSection(GetSectionName("__objc_protorefs",
6603 PTGV->setVisibility(llvm::GlobalValue::HiddenVisibility);
6604 PTGV->setAlignment(Align.getAsAlign());
6606 PTGV->setComdat(CGM.getModule().getOrInsertComdat(ProtocolName));
6608 return CGF.Builder.CreateAlignedLoad(PTGV->getValueType(), PTGV, Align);
6611 /// GenerateCategory - Build metadata for a category implementation.
6624 const ObjCInterfaceDecl *Interface = OCD->getClassInterface();
6628 ExtCatName += Interface->getObjCRuntimeNameAsString();
6630 ExtCatName += OCD->getNameAsString();
6634 values.add(GetClassName(OCD->getIdentifier()->getName()));
6635 // meta-class entry symbol
6638 (Interface->getObjCRuntimeNameAsString() + "_$_" + OCD->getName()).str();
6642 for (const auto *MD : OCD->methods()) {
6643 if (MD->isDirectMethod())
6645 if (MD->isInstanceMethod()) {
6660 instanceMethodList->isNullValue() && classMethodList->isNullValue();
6663 Interface->FindCategoryDeclaration(OCD->getIdentifier());
6667 << Interface->getObjCRuntimeNameAsString() << "_$_" << OCD->getName();
6670 Interface->getObjCRuntimeNameAsString() + "_$_" +
6671 Category->getName(),
6672 Category->protocol_begin(), Category->protocol_end());
6681 isEmptyCategory &= protocolList->isNullValue() &&
6682 propertyList->isNullValue() &&
6683 classPropertyList->isNullValue();
6704 if (Interface->hasAttr<ObjCClassStubAttr>())
6709 // Determine if this category is also "non-lazy".
6716 /// emitMethodConstant - Return a struct objc_method constant. If
6729 method.add(GetMethodVarName(MD->getSelector()));
6744 /// Build meta-data for method declarations.
6815 /// ObjCIvarOffsetVariable - Returns the ivar offset variable for
6820 const ObjCInterfaceDecl *Container = Ivar->getContainingInterface();
6822 Name += Container->getObjCRuntimeNameAsString();
6824 Name += Ivar->getName();
6833 Ivar->getAccessControl() == ObjCIvarDecl::Private ||
6834 Ivar->getAccessControl() == ObjCIvarDecl::Package;
6836 const ObjCInterfaceDecl *ContainingID = Ivar->getContainingInterface();
6838 if (ContainingID->hasAttr<DLLImportAttr>())
6840 ->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
6841 else if (ContainingID->hasAttr<DLLExportAttr>() && !IsPrivateOrPackage)
6843 ->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);
6854 IvarOffsetGV->setInitializer(
6856 IvarOffsetGV->setAlignment(
6862 if (Ivar->getAccessControl() == ObjCIvarDecl::Private ||
6863 Ivar->getAccessControl() == ObjCIvarDecl::Package ||
6864 ID->getVisibility() == HiddenVisibility)
6865 IvarOffsetGV->setVisibility(llvm::GlobalValue::HiddenVisibility);
6867 IvarOffsetGV->setVisibility(llvm::GlobalValue::DefaultVisibility);
6874 IvarOffsetGV->setConstant(true);
6877 IvarOffsetGV->setSection("__DATA, __objc_ivar");
6881 /// EmitIvarList - Emit the ivar list for the given
6908 const ObjCInterfaceDecl *OID = ID->getClassInterface();
6909 assert(OID && "CGObjCNonFragileABIMac::EmitIvarList - null interface");
6913 for (const ObjCIvarDecl *IVD = OID->all_declared_ivar_begin();
6914 IVD; IVD = IVD->getNextIvar()) {
6915 // Ignore unnamed bit-fields.
6916 if (!IVD->getDeclName())
6920 ivar.add(EmitIvarOffsetVar(ID->getClassInterface(), IVD,
6922 ivar.add(GetMethodVarName(IVD->getIdentifier()));
6925 CGM.getTypes().ConvertTypeForMem(IVD->getType());
6928 IVD->getType().getTypePtr()) >> 3;
6952 ivarList, Prefix + OID->getObjCRuntimeNameAsString(), CGM);
6959 llvm::GlobalVariable *&Entry = Protocols[PD->getIdentifier()];
6961 assert(!PD->isNonRuntimeProtocol() &&
6962 "attempting to GetOrEmit a non-runtime protocol");
6969 << PD->getObjCRuntimeNameAsString();
6975 Entry->setComdat(CGM.getModule().getOrInsertComdat(Protocol));
6981 /// GetOrEmitProtocol - Generate the protocol meta-data:
7003 llvm::GlobalVariable *Entry = Protocols[PD->getIdentifier()];
7006 if (Entry && Entry->hasInitializer())
7010 assert(PD->hasDefinition() &&
7012 PD = PD->getDefinition();
7021 values.add(GetClassName(PD->getObjCRuntimeNameAsString()));
7023 + PD->getObjCRuntimeNameAsString(),
7024 PD->protocol_begin(),
7025 PD->protocol_end()));
7035 "_OBJC_$_PROP_LIST_" + PD->getObjCRuntimeNameAsString(),
7042 + PD->getObjCRuntimeNameAsString(),
7050 "_OBJC_$_CLASS_PROP_LIST_" + PD->getObjCRuntimeNameAsString(),
7055 Entry->setLinkage(llvm::GlobalValue::WeakAnyLinkage);
7060 << "_OBJC_PROTOCOL_$_" << PD->getObjCRuntimeNameAsString();
7066 Entry->setComdat(CGM.getModule().getOrInsertComdat(symbolName));
7068 Protocols[PD->getIdentifier()] = Entry;
7070 Entry->setVisibility(llvm::GlobalValue::HiddenVisibility);
7073 // Use this protocol meta-data to build protocol list table in section
7077 << PD->getObjCRuntimeNameAsString();
7084 PTGV->setComdat(CGM.getModule().getOrInsertComdat(ProtocolRef));
7085 PTGV->setAlignment(
7087 PTGV->setSection(GetSectionName("__objc_protolist",
7089 PTGV->setVisibility(llvm::GlobalValue::HiddenVisibility);
7094 /// EmitProtocolList - Generate protocol list meta-data:
7134 // A null-terminated array of protocols.
7149 /// EmitObjCValueForIvar - Code Gen for nonfragile ivar reference.
7161 ObjCInterfaceDecl *ID = ObjectTy->castAs<ObjCObjectType>()->getInterface();
7175 ComputeIvarBaseOffset(CGM, Interface->getImplementation(), Ivar));
7179 CGF.Builder.CreateAlignedLoad(GV->getValueType(), GV,
7183 ->setMetadata(llvm::LLVMContext::MD_invariant_load,
7209 /// Emit a "vtable" message send. We emit a weak hidden-visibility
7215 /// substitutes a stub function which simply tail-calls through the
7217 /// which tail-calls objc_msgSend. Both stubs adjust the selector
7232 // First argument: the receiver / super-call structure.
7252 // except normal, non-super message-sends.
7296 messageRef->setVisibility(llvm::GlobalValue::HiddenVisibility);
7297 messageRef->setSection(GetSectionName("__objc_msgrefs", "coalesced"));
7302 for (const auto *ParamDecl : method->parameters()) {
7303 if (ParamDecl->isDestroyedInCallee()) {
7355 return GetClassGlobal((prefix + ID->getObjCRuntimeNameAsString()).str(),
7357 ID->isWeakImported(),
7360 && ID->hasAttr<DLLImportAttr>());
7372 if (!GV || GV->getValueType() != ObjCTypes.ClassnfABITy) {
7377 NewGV->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
7380 GV->replaceAllUsesWith(NewGV);
7381 GV->eraseFromParent();
7387 assert(GV->getLinkage() == L);
7396 if (!ID->hasAttr<ObjCClassStubAttr>())
7401 // Stub classes are pointer-aligned. Classrefs pointing at stub classes
7411 if (ID && ID->hasAttr<ObjCClassStubAttr>()) {
7412 // Classrefs pointing at Objective-C stub classes must be loaded by calling
7419 return CGF.Builder.CreateAlignedLoad(Entry->getValueType(), Entry, Align);
7433 ClassGV = GetClassGlobal((getClassSymbolPrefix() + II->getName()).str(),
7435 assert(ClassGV->getType() == ObjCTypes.ClassnfABIPtrTy &&
7442 CGM.getModule(), ClassGV->getType(), false,
7445 Entry->setAlignment(CGF.getPointerAlign().getAsAlign());
7446 if (!ID || !ID->hasAttr<ObjCClassStubAttr>())
7447 Entry->setSection(SectionName);
7458 // use the Objective-C runtime to get the class.
7459 if (ID->hasAttr<ObjCRuntimeVisibleAttr>())
7462 return EmitClassRefFromId(CGF, ID->getIdentifier(), ID);
7474 llvm::GlobalVariable *&Entry = SuperClassReferences[ID->getIdentifier()];
7480 Entry = new llvm::GlobalVariable(CGM.getModule(), ClassGV->getType(), false,
7483 Entry->setAlignment(CGF.getPointerAlign().getAsAlign());
7484 Entry->setSection(SectionName);
7491 /// EmitMetaClassRef - Return a Value * of the address of _class_t
7492 /// meta-data
7498 llvm::GlobalVariable * &Entry = MetaClassReferences[ID->getIdentifier()];
7506 Entry->setAlignment(Align.getAsAlign());
7507 Entry->setSection(SectionName);
7514 /// GetClass - Return a reference to the class for the given interface
7518 if (ID->isWeakImported()) {
7522 cast<llvm::GlobalVariable>(ClassGV)->hasExternalWeakLinkage());
7556 Target = EmitMetaClassRef(CGF, Class, Class->isWeakImported());
7581 LI->setMetadata(llvm::LLVMContext::MD_invariant_load,
7596 Entry->setExternallyInitialized(true);
7597 Entry->setSection(SectionName);
7598 Entry->setAlignment(Align.getAsAlign());
7605 /// EmitObjCIvarAssign - Code gen for assigning to a __strong object.
7612 llvm::Type * SrcTy = src->getType();
7627 /// EmitObjCStrongCastAssign - Code gen for assigning to a __strong cast object.
7633 llvm::Type * SrcTy = src->getType();
7657 /// EmitObjCWeakRead - Code gen for loading value of a __weak
7673 /// EmitObjCWeakAssign - Code gen for assigning to a __weak object.
7678 llvm::Type * SrcTy = src->getType();
7694 /// EmitObjCGlobalAssign - Code gen for assigning to a __strong object.
7700 llvm::Type * SrcTy = src->getType();
7730 if (T->isObjCIdType() || T->isObjCQualifiedIdType()) {
7738 IDEHType->setDLLStorageClass(getStorage(CGM, "OBJC_EHTYPE_id"));
7743 // All other types should be Objective-C interface pointer types.
7744 const ObjCObjectPointerType *PT = T->getAs<ObjCObjectPointerType>();
7747 const ObjCInterfaceType *IT = PT->getInterfaceType();
7750 return GetInterfaceEHType(IT->getDecl(), NotForDefinition);
7760 /// EmitThrowStmt - Generate code for a throw statement.
7769 Call->setDoesNotReturn();
7773 Call->setDoesNotReturn();
7784 llvm::GlobalVariable * &Entry = EHTypeReferences[ID->getIdentifier()];
7785 StringRef ClassName = ID->getObjCRuntimeNameAsString();
7806 assert((!Entry || !Entry->hasInitializer()) && "Duplicate EHType definition");
7816 VTableGV->setDLLStorageClass(getStorage(CGM, VTableName));
7823 llvm::ConstantExpr::getInBoundsGetElementPtr(VTableGV->getValueType(),
7833 Entry->setAlignment(CGM.getPointerAlign().getAsAlign());
7842 assert(Entry->getLinkage() == L);
7845 if (ID->getVisibility() == HiddenVisibility)
7846 Entry->setVisibility(llvm::GlobalValue::HiddenVisibility);
7850 Entry->setSection("__DATA,__objc_const");