Lines Matching +full:entry +full:- +full:method
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 //===----------------------------------------------------------------------===//
64 /// the all-integer/pointer case.
66 // Add the non-lazy-bind attribute, since objc_msgSend is likely to
91 /// floating-point stack; without a special entrypoint, the nil case
104 /// would be unbalanced. Only used on 64-bit X86.
180 /// ObjectPtrTy - LLVM type for object handles (typeof(id))
183 /// PtrObjectPtrTy - LLVM type for id *
186 /// SelectorPtrTy - LLVM type for selector handles (typeof(SEL))
190 /// ProtocolPtrTy - LLVM type for external protocol handles
208 // SuperCTy - clang type for struct objc_super.
210 // SuperPtrCTy - clang type for struct objc_super *.
213 /// SuperTy - LLVM type for struct objc_super.
215 /// SuperPtrTy - LLVM type for struct objc_super *.
218 /// PropertyTy - LLVM type for struct objc_property (struct _prop_t
222 /// PropertyListTy - LLVM type for struct objc_property_list
225 /// PropertyListPtrTy - LLVM type for struct objc_property_list*.
228 // MethodTy - LLVM type for struct objc_method.
231 /// CacheTy - LLVM type for struct objc_cache.
233 /// CachePtrTy - LLVM type for struct objc_cache *.
244 Ctx.getPointerDiffType()->getCanonicalTypeUnqualified(), Ctx.BoolTy};
260 Ctx.getPointerDiffType()->getCanonicalTypeUnqualified(),
288 Params.push_back(Ctx.getPointerDiffType()->getCanonicalTypeUnqualified());
365 /// GcReadWeakFn -- LLVM objc_read_weak (id *src) function.
368 llvm::Type *args[] = { ObjectPtrTy->getPointerTo() };
374 /// GcAssignWeakFn -- LLVM objc_assign_weak function.
377 llvm::Type *args[] = { ObjectPtrTy, ObjectPtrTy->getPointerTo() };
383 /// GcAssignGlobalFn -- LLVM objc_assign_global function.
386 llvm::Type *args[] = { ObjectPtrTy, ObjectPtrTy->getPointerTo() };
392 /// GcAssignThreadLocalFn -- LLVM objc_assign_threadlocal function.
395 llvm::Type *args[] = { ObjectPtrTy, ObjectPtrTy->getPointerTo() };
401 /// GcAssignIvarFn -- LLVM objc_assign_ivar function.
404 llvm::Type *args[] = { ObjectPtrTy, ObjectPtrTy->getPointerTo(),
411 /// GcMemmoveCollectableFn -- LLVM objc_memmove_collectable function.
419 /// GcAssignStrongCastFn -- LLVM objc_assign_strongCast function.
422 llvm::Type *args[] = { ObjectPtrTy, ObjectPtrTy->getPointerTo() };
428 /// ExceptionThrowFn - LLVM objc_exception_throw function.
437 /// ExceptionRethrowFn - LLVM objc_exception_rethrow function.
444 /// SyncEnterFn - LLVM object_sync_enter function.
453 /// SyncExitFn - LLVM object_sync_exit function.
497 /// ObjCTypesHelper - Helper class that encapsulates lazy
501 /// SymtabTy - LLVM type for struct objc_symtab.
503 /// SymtabPtrTy - LLVM type for struct objc_symtab *.
505 /// ModuleTy - LLVM type for struct objc_module.
508 /// ProtocolTy - LLVM type for struct objc_protocol.
510 /// ProtocolPtrTy - LLVM type for struct objc_protocol *.
512 /// ProtocolExtensionTy - LLVM type for struct
515 /// ProtocolExtensionTy - LLVM type for struct
518 /// MethodDescriptionTy - LLVM type for struct
521 /// MethodDescriptionListTy - LLVM type for struct
524 /// MethodDescriptionListPtrTy - LLVM type for struct
527 /// ProtocolListTy - LLVM type for struct objc_property_list.
529 /// ProtocolListPtrTy - LLVM type for struct objc_property_list*.
531 /// CategoryTy - LLVM type for struct objc_category.
533 /// ClassTy - LLVM type for struct objc_class.
535 /// ClassPtrTy - LLVM type for struct objc_class *.
537 /// ClassExtensionTy - LLVM type for struct objc_class_ext.
539 /// ClassExtensionPtrTy - LLVM type for struct objc_class_ext *.
541 // IvarTy - LLVM type for struct objc_ivar.
543 /// IvarListTy - LLVM type for struct objc_ivar_list.
545 /// IvarListPtrTy - LLVM type for struct objc_ivar_list *.
547 /// MethodListTy - LLVM type for struct objc_method_list.
549 /// MethodListPtrTy - LLVM type for struct objc_method_list *.
552 /// ExceptionDataTy - LLVM type for struct _objc_exception_data.
555 /// ExceptionTryEnterFn - LLVM objc_exception_try_enter function.
557 llvm::Type *params[] = { ExceptionDataTy->getPointerTo() };
563 /// ExceptionTryExitFn - LLVM objc_exception_try_exit function.
565 llvm::Type *params[] = { ExceptionDataTy->getPointerTo() };
571 /// ExceptionExtractFn - LLVM objc_exception_extract function.
573 llvm::Type *params[] = { ExceptionDataTy->getPointerTo() };
579 /// ExceptionMatchFn - LLVM objc_exception_match function.
587 /// SetJmpFn - LLVM _setjmp function.
590 llvm::Type *params[] = { CGM.Int32Ty->getPointerTo() };
602 /// ObjCNonFragileABITypesHelper - will have all types needed by objective-c's
606 // MethodListnfABITy - LLVM for struct _method_list_t
609 // MethodListnfABIPtrTy - LLVM for struct _method_list_t*
618 // ProtocolListnfABITy - LLVM for struct _objc_protocol_list
621 // ProtocolListnfABIPtrTy - LLVM for struct _objc_protocol_list*
624 // ClassnfABITy - LLVM for struct _class_t
627 // ClassnfABIPtrTy - LLVM for struct _class_t*
630 // IvarnfABITy - LLVM for struct _ivar_t
633 // IvarListnfABITy - LLVM for struct _ivar_list_t
639 // ClassRonfABITy - LLVM for struct _class_ro_t
642 // ImpnfABITy - LLVM for id (*)(id, SEL, ...)
645 // CategorynfABITy - LLVM for struct _category_t
650 // MessageRefTy - LLVM for:
656 // MessageRefCTy - clang type for struct _message_ref_t
659 // MessageRefPtrTy - LLVM for struct _message_ref_t*
661 // MessageRefCPtrTy - clang type for struct _message_ref_t*
664 // SuperMessageRefTy - LLVM for:
671 // SuperMessageRefPtrTy - LLVM for struct _super_message_ref_t*
730 /// Loads from a classref. For Objective-C stub classes, this invokes the
734 // Add the non-lazy-bind attribute, since objc_loadClassref is likely to
752 cast<llvm::Function>(F.getCallee())->setLinkage(
789 /// a non-pointer. Note that this instruction is equal
796 /// subsequent word-size instructions do not begin at a multiple of
805 /// The next I+1 words are __strong pointers to Objective-C
812 /// The next I+1 words are __weak pointers to Objective-C
817 /// Objective-C objects or blocks.
821 /// as-yet-unspecified ownership semantics. If we add more
857 /// LazySymbols - Symbols to generate a lazy reference for. See
861 /// DefinedSymbols - External symbols which are defined by this
863 /// special linker symbols which ensure that Objective-C modules are
867 /// ClassNames - uniqued class names.
870 /// MethodVarNames - uniqued method variable names.
873 /// DefinedCategoryNames - list of category names in form Class_Category.
876 /// MethodVarTypes - uniqued method type signatures. We have to use
880 /// MethodDefinitions - map of methods which have been defined in
884 /// DirectMethodDefinitions - map of direct methods which have been defined in
888 /// PropertyNames - uniqued method variable names.
891 /// ClassReferences - uniqued class references.
894 /// SelectorReferences - uniqued selector references.
897 /// Protocols - Protocols for which an objc_protocol structure has
902 /// DefinedProtocols - Protocols which have actually been
906 /// DefinedClasses - List of defined classes.
909 /// ImplementedClasses - List of @implemented classes.
912 /// DefinedNonLazyClasses - List of defined "non-lazy" classes.
915 /// DefinedCategories - List of defined categories.
918 /// DefinedStubCategories - List of defined categories on class stubs.
921 /// DefinedNonLazyCategories - List of defined "non-lazy" categories.
925 /// int * but is actually an Obj-C class pointer.
933 /// GetMethodVarName - Return a unique constant for the given
938 /// GetMethodVarType - Return a unique constant for the given
939 /// method's type encoding string. The return value has type char *.
946 /// GetPropertyName - Return a unique constant for the given
954 /// GetClassName - Return a unique constant for the given selector's
961 /// BuildIvarLayout - Builds ivar layout bitmap for the class
964 /// \param hasMRCWeakIvars - Whether we are compiling in MRC and there
967 /// actually have any entries, because the ivar might be under-aligned.
1008 /// GetIvarLayoutName - Returns a unique constant for the given
1013 /// EmitPropertyList - Emit the given property list. The return
1021 /// EmitProtocolMethodTypes - Generate the array of extended method type
1027 /// GetProtocolRef - Return a reference to the internal protocol
1041 /// CreateMetadataVar - Create a global variable with internal
1042 /// linkage for use by the Objective-C runtime.
1048 /// \param Name - The variable name.
1049 /// \param Init - The variable initializer; this is also used to
1051 /// \param Section - The section the variable should go into, or empty.
1052 /// \param Align - The alignment for the variable, or 0.
1053 /// \param AddToUsed - Whether the variable should be added to
1082 /// EmitImageInfo - Emit the image info marker used to encode some module
1109 /// GetOrEmitProtocolRef - Get a forward reference to the protocol
1177 for (auto *MD : PD->methods()) {
1178 size_t index = (2 * size_t(MD->isOptional()))
1179 + (size_t(MD->isClassMethod()));
1188 // In both ABIs, the method types list is parallel with the
1199 result.push_back(self->GetMethodVarType(MD, true));
1209 return self->emitMethodList(PD->getObjCRuntimeNameAsString(),
1222 /// EmitModuleInfo - Another marker encoding module level
1226 /// EmitModuleSymols - Emit module symbols, the list of defined
1230 /// FinishModule - Write out global data structures at the end of
1234 /// EmitClassExtension - Generate the class extension structure used
1242 /// EmitClassRef - Return a Value*, of type ObjCTypes.ClassPtrTy,
1252 /// EmitSuperClassRef - Emits reference to class's main metadata class.
1255 /// EmitIvarList - Emit the ivar list for the given
1263 /// EmitMetaClass - Emit a forward reference to the class structure
1268 /// EmitMetaClass - Emit a class structure for the metaclass of the
1280 /// EmitMethodList - Emit the method list for the given
1285 /// GetOrEmitProtocol - Get the protocol object for the given
1290 /// GetOrEmitProtocolRef - Get a forward reference to the protocol
1296 /// EmitProtocolExtension - Generate the protocol extension
1304 /// EmitProtocolList - Generate the list of referenced
1310 /// EmitSelector - Return a Value*, of type ObjCTypes.SelectorPtrTy,
1328 const ObjCMethodDecl *Method) override;
1336 const ObjCMethodDecl *Method) override;
1347 const ObjCMethodDecl *Method) override;
1408 /// SuperClassReferences - uniqued super class references.
1411 /// MetaClassReferences - uniqued meta class references.
1414 /// EHTypeReferences - uniqued class ehtype references.
1417 /// VTableDispatchMethods - List of methods for which we generate
1418 /// vtable-based message dispatch.
1421 /// DefinedMetaClasses - List of defined meta-classes.
1424 /// isVTableDispatchedSelector - Returns true if SEL is a
1425 /// vtable-based selector.
1428 /// FinishNonFragileABIModule - Write out global data structures at the end of
1432 /// AddModuleClassList - Add the given list of class pointers to the
1452 /// Emit the method list for the given implementation. The return value
1457 /// EmitIvarList - Emit the ivar list for the given
1468 /// GetOrEmitProtocol - Get the protocol object for the given
1473 /// GetOrEmitProtocolRef - Get a forward reference to the protocol
1479 /// EmitProtocolList - Generate the list of referenced
1493 const ObjCMethodDecl *Method);
1495 /// GetClassGlobal - Return the global variable for the Objective-C
1508 llvm::GlobalVariable *Entry);
1510 /// EmitClassRef - Return a Value*, of type ObjCTypes.ClassPtrTy,
1521 /// EmitSuperClassRef - Return a Value*, of type ObjCTypes.ClassPtrTy,
1526 /// EmitMetaClassRef - Return a Value * of the address of _class_t
1527 /// meta-data
1531 /// ObjCIvarOffsetVariable - Returns the ivar offset variable for
1538 /// EmitSelector - Return a Value*, of type ObjCTypes.SelectorPtrTy,
1543 /// GetInterfaceEHType - Get the cached ehtype for the given Objective-C
1567 /// ImplementationIsNonLazy - Check whether the given category or
1568 /// class implementation is "non-lazy".
1573 // Annotate the load as an invariant load iff inside an instance method
1574 // and ivar belongs to instance method's class and one of its super class.
1580 // base of the ivar access is a parameter to an Objective C method.
1585 // and that the method may be inlined, this optimization actually
1589 if (MD->isInstanceMethod() && !MD->isDirectMethod())
1590 if (const ObjCInterfaceDecl *ID = MD->getClassInterface())
1591 return IV->getContainingInterface()->isSuperClassOf(ID);
1598 for (; ID; ID = ID->getSuperClass()) {
1601 if (ID->getIdentifier()->getName() == "NSObject")
1606 if (!ID->getImplementation())
1625 const ObjCMethodDecl *Method) override;
1633 const ObjCMethodDecl *Method) override;
1646 const ObjCMethodDecl *Method) override
1647 { return EmitSelector(CGF, Method->getSelector()); }
1721 /// A helper class for performing the null-initialization of a return
1727 /// Perform a null-check of the given receiver.
1729 // Make blocks for the null-receiver and call edges.
1730 NullBB = CGF.createBasicBlock("msgSend.null-receiver");
1734 // null-receiver block. There's no point in trying to avoid it:
1736 // we shouldn't have done this null-check in the first place.
1744 /// Complete the null-return operation. It is valid to call this
1751 const ObjCMethodDecl *Method) {
1752 // If we never had to do a null-check, just use the raw result.
1756 // IP, which can happen if the method we're calling is marked noreturn.
1766 // Okay, start emitting the null-receiver block.
1770 if (Method) {
1771 CGObjCRuntime::destroyCalleeDestroyedArguments(CGF, Method, CallArgs);
1778 if (result.isScalar() && resultType->isVoidType()) {
1779 // No jumps required if the message-send was noreturn.
1786 // Derive the null-initialization value.
1795 llvm::PHINode *phi = CGF.Builder.CreatePHI(null->getType(), 2);
1796 phi->addIncoming(result.getScalarVal(), callBB);
1797 phi->addIncoming(null, NullBB);
1803 // cases where the ABI has us returning (1) non-agg values in
1806 assert(result.isAggregate() && "null init of non-aggregate result?");
1818 llvm::Type *scalarTy = callResult.first->getType();
1823 real->addIncoming(callResult.first, callBB);
1824 real->addIncoming(scalarZero, NullBB);
1826 imag->addIncoming(callResult.second, callBB);
1827 imag->addIncoming(scalarZero, NullBB);
1836 /// getConstantGEP() - Help routine to construct simple GEPs.
1844 return llvm::ConstantExpr::getGetElementPtr(C->getValueType(), C, Idxs);
1847 /// hasObjCExceptionAttribute - Return true if this class or any super
1851 if (OID->hasAttr<ObjCExceptionAttr>())
1853 if (const ObjCInterfaceDecl *Super = OID->getSuperClass())
1876 GV->setSection(SectionName);
1888 /// GetClass - Return a reference to the class for the given interface
1895 /// GetSelector - Return the pointer to the unique'd string for this selector.
1903 *Method) {
1904 return EmitSelector(CGF, Method->getSelector());
1908 if (T->isObjCIdType() ||
1909 T->isObjCQualifiedIdType()) {
1913 if (T->isObjCClassType() ||
1914 T->isObjCQualifiedClassType()) {
1918 if (T->isObjCObjectPointerType())
1953 StringRef String = Literal->getString();
1989 llvm::StringMapEntry<llvm::GlobalVariable *> &Entry =
1992 if (auto *C = Entry.second)
1994 C, C->getValueType(), CharUnits::fromQuantity(C->getAlignment()));
2014 llvm::ConstantDataArray::getString(VMContext, Entry.first());
2019 auto *GV = new llvm::GlobalVariable(CGM.getModule(), C->getType(), isConstant,
2021 GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
2024 GV->setAlignment(llvm::Align(1));
2039 GV->setSection(CGM.getLangOpts().ObjCRuntime.isNonFragile()
2042 Entry.second = GV;
2044 return ConstantAddress(GV, GV->getValueType(), Alignment);
2053 /// which class's method should be called.
2064 const ObjCMethodDecl *Method) {
2079 // Message sent to 'super' in a class method defined in a category
2081 // If we are in a class method, we must retrieve the
2085 Target = EmitClassRef(CGF, Class->getSuperClass());
2098 Target = EmitClassRef(CGF, Class->getSuperClass());
2112 ObjCTypes.SuperPtrCTy, true, CallArgs, Method, Class,
2124 const ObjCMethodDecl *Method) {
2127 Method, Class, ObjCTypes);
2139 const ObjCMethodDecl *Method,
2150 if (!Method || !Method->isDirectMethod())
2154 // If we're calling a method, use the formal signature.
2155 MessageSendInfo MSI = getMessageSendInfo(Method, ResultType, ActualArgs);
2157 if (Method)
2158 assert(CGM.getContext().getCanonicalType(Method->getReturnType()) ==
2163 canMessageReceiverBeNull(CGF, Method, IsSuper, ClassReceiver, Arg0);
2169 if (Method && Method->isDirectMethod()) {
2171 Fn = GenerateDirectMethod(Method, Method->getClassInterface());
2203 // Emit a null-check if there's a consumed argument other than the receiver.
2204 if (!RequiresNullCheck && Method && Method->hasParamDestroyedInCallee())
2223 // Mark the call as noreturn if the method is marked noreturn and the
2225 if (Method && Method->hasAttr<NoReturnAttr>() && !ReceiverCanBeNull) {
2226 CallSite->setDoesNotReturn();
2230 RequiresNullCheck ? Method : nullptr);
2258 if (FQT->isObjCObjectPointerType() || FQT->isBlockPointerType())
2263 if (const PointerType *PT = FQT->getAs<PointerType>())
2264 return GetGCAttrTypeForType(Ctx, PT->getPointeeType(), /*pointee*/ true);
2297 /// Whether the offsets in IvarsInfo might be out-of-order.
2377 for (const auto &CI : blockDecl->captures()) {
2379 QualType type = variable->getType();
2389 // adding them out-of-order, make sure we sort later.
2400 assert(!type->isArrayType() && "array variable should not be caught");
2401 if (const RecordType *record = type->getAs<RecordType>()) {
2416 /// getBlockCaptureLifetime - This routine returns life time of the captured
2417 /// block variable for the purpose of block layout meta-data generation. FQT is
2429 // In MRC, retainable pointers are owned by non-__block variables.
2430 if (FQT->isObjCObjectPointerType() || FQT->isBlockPointerType())
2464 bool IsUnion = (RD && RD->isUnion());
2484 if (!Field->getIdentifier() || Field->isBitField()) {
2491 QualType FQT = Field->getType();
2492 if (FQT->isRecordType() || FQT->isUnionType()) {
2493 if (FQT->isUnionType())
2496 BuildRCBlockVarRecordLayout(FQT->castAs<RecordType>(),
2503 uint64_t ElCount = CArray->getZExtSize();
2505 FQT = CArray->getElementType();
2508 ElCount *= CArray->getZExtSize();
2509 FQT = CArray->getElementType();
2511 if (FQT->isRecordType() && ElCount) {
2512 int OldIndex = RunSkipBlockVars.size() - 1;
2513 auto *RT = FQT->castAs<RecordType>();
2519 for (int FirstIndex = RunSkipBlockVars.size() - 1 ;ElIx < ElCount; ElIx++) {
2530 CharUnits FieldSize = CGM.getContext().getTypeSizeInChars(Field->getType());
2547 if (LastFieldBitfieldOrUnnamed->isBitField()) {
2550 = LastFieldBitfieldOrUnnamed->getBitWidthValue(CGM.getContext());
2556 getBlockCaptureLifetime(LastFieldBitfieldOrUnnamed->getType(),
2561 assert(!LastFieldBitfieldOrUnnamed->getIdentifier() &&"Expected unnamed");
2564 = CGM.getContext().getTypeSizeInChars(LastFieldBitfieldOrUnnamed->getType());
2566 getBlockCaptureLifetime(LastFieldBitfieldOrUnnamed->getType(),
2575 getBlockCaptureLifetime(MaxField->getType(), ByrefLayout),
2584 const RecordDecl *RD = RT->getDecl();
2585 SmallVector<const FieldDecl*, 16> Fields(RD->fields());
2593 /// InlineLayoutInstruction - This routine produce an inline instruction for the
2727 end_byte_pos - start_byte_pos + RunSkipBlockVars[j-1].block_var_size;
2730 RunSkipBlockVars[j].block_var_bytepos -
2731 RunSkipBlockVars[j-1].block_var_bytepos - RunSkipBlockVars[j-1].block_var_size;
2737 size_in_bytes -= residue_in_bytes;
2747 size_in_words -= 16;
2752 unsigned char inst = (opcode << 4) | (size_in_words-1);
2757 (BLOCK_LAYOUT_NON_OBJECT_BYTES << 4) | (residue_in_bytes.getQuantity()-1);
2833 if (i < e-1)
2840 auto *Entry = CreateCStringLiteral(BitMap, ObjCLabelType::ClassName,
2843 return getConstantGEP(VMContext, Entry, 0, 0);
2859 // happens when the block is non-escaping).
2906 for (const auto &CI : blockDecl->captures()) {
2908 QualType type = variable->getType();
2916 CharUnits::fromQuantity(layout->getElementOffset(capture.getIndex()));
2918 assert(!type->isArrayType() && "array variable should not be caught");
2920 if (const RecordType *record = type->getAs<RecordType>()) {
2950 assert(!T->isArrayType() && "__block array variable should not be caught");
2954 if (const RecordType *record = T->getAs<RecordType>()) {
2977 DefinedProtocols.insert(PD->getIdentifier());
2982 if (Protocols.count(PD->getIdentifier()))
2987 if (DefinedProtocols.count(PD->getIdentifier()))
3001 ID->getObjCRuntimeNameAsString()))
3009 call->setDoesNotThrow();
3014 // Objective-C 1.0 extensions
3026 llvm::GlobalVariable *Entry = Protocols[PD->getIdentifier()];
3029 if (Entry && Entry->hasInitializer())
3030 return Entry;
3033 if (const ObjCProtocolDecl *Def = PD->getDefinition())
3040 // Construct method lists.
3046 values.add(GetClassName(PD->getObjCRuntimeNameAsString()));
3047 values.add(EmitProtocolList("OBJC_PROTOCOL_REFS_" + PD->getName(),
3048 PD->protocol_begin(), PD->protocol_end()));
3054 if (Entry) {
3056 assert(Entry->hasPrivateLinkage());
3057 values.finishAndSetAsInitializer(Entry);
3059 Entry = values.finishAndCreateGlobal("OBJC_PROTOCOL_" + PD->getName(),
3063 Entry->setSection("__OBJC,__protocol,regular,no_dead_strip");
3065 Protocols[PD->getIdentifier()] = Entry;
3067 CGM.addCompilerUsedGlobal(Entry);
3069 return Entry;
3073 llvm::GlobalVariable *&Entry = Protocols[PD->getIdentifier()];
3075 if (!Entry) {
3079 Entry = new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ProtocolTy,
3081 nullptr, "OBJC_PROTOCOL_" + PD->getName());
3082 Entry->setSection("__OBJC,__protocol,regular,no_dead_strip");
3084 Entry->setAlignment(llvm::Align(4));
3087 return Entry;
3111 EmitProtocolMethodTypes("OBJC_PROTOCOL_METHOD_TYPES_" + PD->getName(),
3116 EmitPropertyList("OBJC_$_PROP_PROTO_LIST_" + PD->getName(), nullptr, PD,
3119 EmitPropertyList("OBJC_$_CLASS_PROP_PROTO_LIST_" + PD->getName(), nullptr,
3123 if (optInstanceMethods->isNullValue() &&
3124 optClassMethods->isNullValue() &&
3125 extendedMethodTypes->isNullValue() &&
3126 instanceProperties->isNullValue() &&
3127 classProperties->isNullValue()) {
3144 return CreateMetadataVar("_OBJC_PROTOCOLEXT_" + PD->getName(), values,
3199 for (const auto *PD : Proto->properties()) {
3200 if (IsClassProperty != PD->isClassProperty())
3202 if (!PropertySet.insert(PD->getIdentifier()).second)
3207 for (const auto *P : Proto->protocols())
3229 // Make this entry NULL for OS X with deployment target < 10.11, for iOS
3241 for (const ObjCCategoryDecl *ClassExt : OID->known_extensions())
3242 for (auto *PD : ClassExt->properties()) {
3243 if (IsClassProperty != PD->isClassProperty())
3245 if (PD->isDirectProperty())
3247 PropertySet.insert(PD->getIdentifier());
3251 for (const auto *PD : OCD->properties()) {
3252 if (IsClassProperty != PD->isClassProperty())
3256 if (!PropertySet.insert(PD->getIdentifier()).second)
3258 if (PD->isDirectProperty())
3264 for (const auto *P : OID->all_referenced_protocols())
3268 for (const auto *P : CD->protocols())
3286 property.add(GetPropertyName(PD->getIdentifier()));
3342 const ObjCInterfaceDecl *Interface = OCD->getClassInterface();
3344 Interface->FindCategoryDeclaration(OCD->getIdentifier());
3347 llvm::raw_svector_ostream(ExtName) << Interface->getName() << '_'
3348 << OCD->getName();
3359 for (const auto *MD : OCD->methods()) {
3360 if (!MD->isDirectMethod())
3361 Methods[unsigned(MD->isClassMethod())].push_back(MD);
3364 Values.add(GetClassName(OCD->getName()));
3365 Values.add(GetClassName(Interface->getObjCRuntimeNameAsString()));
3366 LazySymbols.insert(Interface->getIdentifier());
3375 Category->protocol_begin(), Category->protocol_end()));
3398 // method definition entries must be clear for next implementation.
3403 /// Apparently: is not a meta-class.
3406 /// Is a meta-class.
3409 /// Has a non-trivial constructor or destructor.
3424 /// Is a meta-class.
3430 /// Has a non-trivial constructor or destructor.
3439 /// (Obsolete) ARC-specific: this class has a .release_ivars method
3445 /// Class has non-trivial destructors, but zero-initialization is okay.
3458 if (auto recType = type->getAs<RecordType>()) {
3459 for (auto *field : recType->getDecl()->fields()) {
3460 if (hasWeakMember(field->getType()))
3477 ID->getClassInterface()->all_declared_ivar_begin();
3478 ivar; ivar = ivar->getNextIvar()) {
3479 if (hasWeakMember(ivar->getType()))
3498 // Objective-C 1.0 extensions (<rdr://4585769>)
3507 &CGM.getContext().Idents.get(ID->getObjCRuntimeNameAsString());
3510 std::string ClassName = ID->getNameAsString();
3513 const_cast<ObjCInterfaceDecl*>(ID->getClassInterface());
3515 EmitProtocolList("OBJC_CLASS_PROTOCOLS_" + ID->getName(),
3516 Interface->all_referenced_protocol_begin(),
3517 Interface->all_referenced_protocol_end());
3519 if (ID->hasNonZeroConstructors() || ID->hasDestructors())
3532 // FIXME: Set CXX-structors flag.
3533 if (ID->getClassInterface()->getVisibility() == HiddenVisibility)
3542 for (const auto *MD : ID->methods()) {
3543 if (!MD->isDirectMethod())
3544 Methods[unsigned(MD->isClassMethod())].push_back(MD);
3547 for (const auto *PID : ID->property_impls()) {
3548 if (PID->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize) {
3549 if (PID->getPropertyDecl()->isDirectProperty())
3551 if (ObjCMethodDecl *MD = PID->getGetterMethodDecl())
3554 if (ObjCMethodDecl *MD = PID->getSetterMethodDecl())
3563 if (ObjCInterfaceDecl *Super = Interface->getSuperClass()) {
3565 LazySymbols.insert(Super->getIdentifier());
3567 values.add(GetClassName(Super->getObjCRuntimeNameAsString()));
3571 values.add(GetClassName(ID->getObjCRuntimeNameAsString()));
3577 values.add(emitMethodList(ID->getName(), MethodListType::InstanceMethods,
3592 assert(GV->getValueType() == ObjCTypes.ClassTy &&
3595 GV->setSection(Section);
3596 GV->setAlignment(CGM.getPointerAlign().getAsAlign());
3602 // method definition entries must be clear for next implementation.
3612 if (ID->getClassInterface()->getVisibility() == HiddenVisibility)
3618 const ObjCInterfaceDecl *Root = ID->getClassInterface();
3619 while (const ObjCInterfaceDecl *Super = Root->getSuperClass())
3621 values.add(GetClassName(Root->getObjCRuntimeNameAsString()));
3625 if (ObjCInterfaceDecl *Super = ID->getClassInterface()->getSuperClass()) {
3626 values.add(GetClassName(Super->getObjCRuntimeNameAsString()));
3630 values.add(GetClassName(ID->getObjCRuntimeNameAsString()));
3636 values.add(emitMethodList(ID->getName(), MethodListType::ClassMethods,
3648 Name += ID->getName();
3653 assert(GV->getValueType() == ObjCTypes.ClassTy &&
3661 GV->setSection("__OBJC,__meta_class,regular,no_dead_strip");
3668 std::string Name = "OBJC_METACLASS_" + ID->getNameAsString();
3684 assert(GV->getValueType() == ObjCTypes.ClassTy &&
3690 std::string Name = "OBJC_CLASS_" + ID->getNameAsString();
3698 assert(GV->getValueType() == ObjCTypes.ClassTy &&
3705 data that doesn't fit in the normal fragile-ABI class structure, and
3731 + ID->getName(),
3732 ID, ID->getClassInterface(), ObjCTypes, isMetaclass);
3735 if (layout->isNullValue() && propertyList->isNullValue()) {
3748 return CreateMetadataVar("OBJC_CLASSEXT_" + ID->getName(), values,
3775 const ObjCInterfaceDecl *OID = ID->getClassInterface();
3782 for (const ObjCIvarDecl *IVD = OID->all_declared_ivar_begin();
3783 IVD; IVD = IVD->getNextIvar()) {
3784 // Ignore unnamed bit-fields.
3785 if (!IVD->getDeclName())
3789 ivar.add(GetMethodVarName(IVD->getIdentifier()));
3807 GV = CreateMetadataVar("OBJC_INSTANCE_VARIABLES_" + ID->getName(), ivarList,
3813 /// Build a struct objc_method_description constant for the given method.
3822 description.add(GetMethodVarName(MD->getSelector()));
3827 /// Build a struct objc_method constant for the given method.
3832 /// void *method;
3837 assert(fn && "no definition registered for method");
3839 auto method = builder.beginStruct(ObjCTypes.MethodTy);
3840 method.add(GetMethodVarName(MD->getSelector()));
3841 method.add(GetMethodVarType(MD));
3842 method.add(fn);
3843 method.finishAndAddTo(builder);
3937 if (!MD->isDirectMethod())
3949 llvm::Function *Method;
3951 if (OMD->isDirectMethod()) {
3952 Method = GenerateDirectMethod(OMD, CD);
3959 Method =
3964 MethodDefinitions.insert(std::make_pair(OMD, Method));
3966 return Method;
3972 auto *COMD = OMD->getCanonicalDecl();
3977 // Objective-C allows for the declaration and implementation types
3980 // If we're being asked for the Function associated for a method
3986 if (!OMD->getBody() || COMD->getReturnType() == OMD->getReturnType())
3987 return I->second;
3988 OldFn = I->second;
3998 Fn->takeName(OldFn);
3999 OldFn->replaceAllUsesWith(Fn);
4000 OldFn->eraseFromParent();
4003 I->second = Fn;
4020 auto selfAddr = CGF.GetAddrOfLocalVar(OMD->getSelfDecl());
4036 if (OMD->isClassMethod()) {
4045 // TODO: If this method is inlined, the caller might know that `self` is
4046 // already initialized; for example, it might be an ordinary Objective-C
4047 // method which always receives an initialized `self`, or it might have just
4057 // Nullable `Class` expressions cannot be messaged with a direct method
4070 auto selfTy = cast<llvm::PointerType>(selfValue->getType());
4080 auto retTy = OMD->getReturnType();
4082 if (!retTy->isVoidType()) {
4094 if (OMD->getCmdDecl()->isUsed()) {
4097 CGF.EmitVarDecl(*OMD->getCmdDecl());
4099 CGF.GetAddrOfLocalVar(OMD->getCmdDecl()));
4113 GV->setSection(Section);
4124 llvm::Type *Ty = Init->getType();
4130 GV->setSection(Section);
4131 GV->setAlignment(Align.getAsAlign());
4174 new llvm::GlobalVariable(CGM.getModule(), Value->getType(),
4178 GV->setSection(Section);
4179 GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
4180 GV->setAlignment(CharUnits::One().getAsAlign());
4276 CGF.EmitStmt(FinallyStmt->getFinallyBody());
4316 /// Create the fragile-ABI read and write hazards based on the current
4328 I = CGF.CurFn->begin(), E = CGF.CurFn->end(); I != E; ++I)
4333 // Create a read hazard for the allocas. This inhibits dead-store
4369 Call->addParamAttr(Pair.index(), llvm::Attribute::get(
4371 cast<llvm::AllocaInst>(Pair.value())->getAllocatedType()));
4377 call->setDoesNotThrow();
4378 call->setCallingConv(CGF.getRuntimeCC());
4380 call->addParamAttr(Pair.index(), llvm::Attribute::get(
4382 cast<llvm::AllocaInst>(Pair.value())->getAllocatedType()));
4394 FI = CGF.CurFn->begin(), FE = CGF.CurFn->end(); FI != FE; ++FI) {
4403 // Ignore instructions that aren't non-intrinsic calls.
4440 llvm::BasicBlock &Entry = CGF.CurFn->getEntryBlock();
4442 I = Entry.begin(), E = Entry.end(); I != E; ++I)
4450 tys[i] = Locals[i]->getType();
4456 Objective-C setjmp-longjmp (sjlj) Exception Handling
4457 --
4460 - a pointer to the exception that was caught
4461 - a pointer to the previous exception data buffer
4462 - two pointers of reserved storage
4464 of the stack kept in thread-local storage.
4476 There's no reason an implementation couldn't use a light-weight
4477 setjmp here --- something like __builtin_setjmp, but API-compatible
4485 inhibit optimizing locals across the setjmp->catch edge.
4487 The basic framework for a @try-catch-finally is as follows:
4506 ... jump-through-finally to finally_rethrow ...
4511 ... jump-through-finally to finally_rethrow ...
4514 ... jump-through-finally to finally_end ...
4536 - If there are no catch blocks, then we avoid emitting the second
4539 - If there is a catch-all catch block (i.e. @catch(...) or @catch(id
4542 - FIXME: If there is no @finally block we can do a few more
4545 Rethrows and Jumps-Through-Finally
4546 --
4548 '@throw;' is supported by pushing the currently-caught exception
4552 normal cleanup. We do not register an EH cleanup; fragile-ABI ObjC
4566 // A destination for the fall-through edges of the catch handlers to
4588 SyncArgSlot = CGF.CreateTempAlloca(SyncArg->getType(),
4607 // - no catches match and we're branching through the cleanup
4609 // - a catch matched and we're falling out of the catch handler.
4610 // The setjmp-safety rule here is that we should always store to this
4629 // - Call objc_exception_try_enter to push ExceptionData on top of
4634 // - Call setjmp on the exception data buffer.
4642 SetJmpResult->setCanReturnTwice();
4663 // Don't optimize loads of the in-scope locals across this point.
4669 // Tell the cleanup not to re-pop the exit.
4687 bool HasFinally = (AtTryStmt->getFinallyStmt() != nullptr);
4692 // Save the currently-propagating exception before
4694 PropagatingExnVar = CGF.CreateTempAlloca(Caught->getType(),
4707 SetJmpResult->setCanReturnTwice();
4725 for (const ObjCAtCatchStmt *CatchStmt : AtTryStmt->catch_stmts()) {
4726 const VarDecl *CatchParam = CatchStmt->getCatchParamDecl();
4733 OPT = CatchParam->getType()->getAs<ObjCObjectPointerType>();
4739 if (OPT && (OPT->isObjCIdType() || OPT->isObjCQualifiedIdType()))
4743 // If this is a catch-all, we don't need to test anything.
4755 CGF.EmitStmt(CatchStmt->getCatchBody());
4764 assert(OPT && "Unexpected non-object pointer type in @catch");
4765 const ObjCObjectType *ObjTy = OPT->getObjectType();
4768 ObjCInterfaceDecl *IDecl = ObjTy->getInterface();
4769 assert(IDecl && "Catch parameter must have Objective-C type!");
4798 CGF.ConvertType(CatchParam->getType()));
4801 CGF.EmitStmt(CatchStmt->getCatchBody());
4815 if (Caught->use_empty())
4816 Caught->eraseFromParent();
4826 // unnecessary because there's no local-accessing code between
4831 // propagating-exception slot.
4858 // If we have a propagating-exception variable, check it.
4894 ->setDoesNotReturn();
4902 /// EmitObjCWeakRead - Code gen for loading value of a __weak
4917 /// EmitObjCWeakAssign - Code gen for assigning to a __weak object.
4922 llvm::Type * SrcTy = src->getType();
4938 /// EmitObjCGlobalAssign - Code gen for assigning to a __strong object.
4944 llvm::Type * SrcTy = src->getType();
4964 /// EmitObjCIvarAssign - Code gen for assigning to a __strong object.
4970 assert(ivarOffset && "EmitObjCIvarAssign - ivarOffset is NULL");
4971 llvm::Type * SrcTy = src->getType();
4986 /// EmitObjCStrongCastAssign - Code gen for assigning to a __strong cast object.
4991 llvm::Type * SrcTy = src->getType();
5015 /// EmitObjCValueForIvar - Code Gen for ivar reference.
5023 ObjectTy->castAs<ObjCObjectType>()->getInterface();
5061 "Objective-C support is unimplemented for object file format");
5067 /// EmitImageInfo - Emit the image info marker used to encode some module
5096 // Generate module-level named metadata to convey this information to the
5097 // linker and code-gen.
5101 Mod.addModuleFlag(llvm::Module::Error, "Objective-C Version", ObjCABI);
5102 Mod.addModuleFlag(llvm::Module::Error, "Objective-C Image Info Version",
5104 Mod.addModuleFlag(llvm::Module::Error, "Objective-C Image Info Section",
5109 // Non-GC overrides those files which specify GC.
5111 "Objective-C Garbage Collection",
5116 "Objective-C Garbage Collection",
5122 Mod.addModuleFlag(llvm::Module::Error, "Objective-C GC Only",
5127 llvm::MDString::get(VMContext, "Objective-C Garbage Collection"),
5130 Mod.addModuleFlag(llvm::Module::Require, "Objective-C GC Only",
5137 Mod.addModuleFlag(llvm::Module::Error, "Objective-C Is Simulated",
5141 Mod.addModuleFlag(llvm::Module::Error, "Objective-C Class Properties",
5191 if (ObjCImplementationDecl *IMP = ID->getImplementation())
5193 if (ID->isWeakImported() && !IMP->isWeakImported())
5194 DefinedClasses[i]->setLinkage(llvm::GlobalVariable::ExternalLinkage);
5213 llvm::GlobalVariable *&Entry = ClassReferences[II];
5215 if (!Entry) {
5216 Entry =
5217 CreateMetadataVar("OBJC_CLASS_REFERENCES_", GetClassName(II->getName()),
5222 return CGF.Builder.CreateAlignedLoad(Entry->getValueType(), Entry,
5229 // use the Objective-C runtime to get the class.
5230 if (ID->hasAttr<ObjCRuntimeVisibleAttr>())
5234 &CGM.getContext().Idents.get(ID->getObjCRuntimeNameAsString());
5250 llvm::GlobalVariable *&Entry = SelectorReferences[Sel];
5251 if (!Entry) {
5252 Entry = CreateMetadataVar(
5255 Entry->setExternallyInitialized(true);
5258 return ConstantAddress(Entry, ObjCTypes.SelectorPtrTy, Align);
5262 llvm::GlobalVariable *&Entry = ClassNames[RuntimeName];
5263 if (!Entry)
5264 Entry = CreateCStringLiteral(RuntimeName, ObjCLabelType::ClassName);
5265 return getConstantGEP(VMContext, Entry, 0, 0);
5272 /// GetIvarLayoutName - Returns a unique constant for the given
5281 const RecordDecl *RD = RT->getDecl();
5285 if (RD->isUnion())
5289 visitAggregate(RD->field_begin(), RD->field_end(), offset,
5290 [&](const FieldDecl *field) -> CharUnits {
5293 auto offsetInBits = recLayout->getFieldOffset(field->getFieldIndex());
5306 if (field->isBitField()) {
5320 QualType fieldType = field->getType();
5326 fieldType = arrayType->getElementType();
5330 numElts *= arrayType->getZExtSize();
5331 fieldType = arrayType->getElementType();
5334 assert(!fieldType->isArrayType() && "ivar of non-constant array type?");
5336 // If we ended up with a zero-sized array, we've done what we can do within
5341 if (auto recType = fieldType->getAs<RecordType>()) {
5346 // If we have an array, replicate the first entry's layout information.
5347 auto numEltEntries = IvarsInfo.size() - oldEnd;
5367 // If it matches what we're looking for, add an entry.
5376 /// buildBitmap - This routine does the horsework of taking the offsets of
5410 unsigned claimed = std::min(MaxNibble - lastSkip, numWords);
5411 numWords -= claimed;
5419 numWords -= MaxNibble;
5435 unsigned claimed = std::min(MaxNibble - lastScan, numWords);
5436 numWords -= claimed;
5444 numWords -= MaxNibble;
5457 CharUnits beginOfScan = request.Offset - InstanceBegin;
5465 // isn't the true start of the ivars, because in the fragile-ARC case
5479 skip(beginOfScanInWords - endOfLastScanInWords);
5491 scan(endOfScanInWords - beginOfScanInWords);
5500 // or necessary for the ARC-style layout strings.
5503 (InstanceEnd - InstanceBegin + WordSize - CharUnits::One()) / WordSize;
5505 skip(lastOffsetInWords - endOfLastScanInWords);
5512 auto *Entry = CGObjC.CreateCStringLiteral(
5514 return getConstantGEP(CGM.getLLVMContext(), Entry, 0, 0);
5517 /// BuildIvarLayout - Builds ivar layout bitmap for the class
5521 /// Each byte is divided up in two nibbles (4-bit each). Left nibble is count
5526 /// - id, Class
5527 /// - object *
5528 /// - __strong anything
5531 /// - __weak anything
5545 const ObjCInterfaceDecl *OI = OMD->getClassInterface();
5549 // inaccurately in the non-fragile ABI; the runtime knows how to fix this
5552 // ARC layout strings only include the class's ivars. In non-fragile
5560 for (const ObjCIvarDecl *IVD = OI->all_declared_ivar_begin();
5561 IVD; IVD = IVD->getNextIvar())
5587 [&](const ObjCIvarDecl *ivar) -> CharUnits {
5600 OMD->getClassInterface()->getName().str().c_str());
5607 llvm::GlobalVariable *&Entry = MethodVarNames[Sel];
5609 if (!Entry)
5610 Entry = CreateCStringLiteral(Sel.getAsString(), ObjCLabelType::MethodVarName);
5611 return getConstantGEP(VMContext, Entry, 0, 0);
5621 CGM.getContext().getObjCEncodingForType(Field->getType(), TypeStr, Field);
5623 llvm::GlobalVariable *&Entry = MethodVarTypes[TypeStr];
5624 if (!Entry)
5625 Entry = CreateCStringLiteral(TypeStr, ObjCLabelType::MethodVarType);
5626 return getConstantGEP(VMContext, Entry, 0, 0);
5634 llvm::GlobalVariable *&Entry = MethodVarTypes[TypeStr];
5635 if (!Entry)
5636 Entry = CreateCStringLiteral(TypeStr, ObjCLabelType::MethodVarType);
5637 return getConstantGEP(VMContext, Entry, 0, 0);
5642 llvm::GlobalVariable *&Entry = PropertyNames[Ident];
5643 if (!Entry)
5644 Entry = CreateCStringLiteral(Ident->getName(), ObjCLabelType::PropertyName);
5645 return getConstantGEP(VMContext, Entry, 0, 0);
5663 for (auto &entry : Protocols) {
5664 llvm::GlobalVariable *global = entry.second;
5665 if (global->hasInitializer())
5671 values.add(GetClassName(entry.first->getName()));
5693 OS << "\t.objc_class_name_" << Sym->getName() << "=0\n"
5694 << "\t.globl .objc_class_name_" << Sym->getName() << "\n";
5696 OS << "\t.lazy_reference .objc_class_name_" << Sym->getName() << "\n";
5756 RD->addDecl(FieldDecl::Create(Ctx, RD, SourceLocation(), SourceLocation(),
5759 RD->addDecl(FieldDecl::Create(Ctx, RD, SourceLocation(), SourceLocation(),
5762 RD->completeDefinition();
5845 ProtocolListTy->setBody(llvm::PointerType::getUnqual(ProtocolListTy), LongTy,
5855 ProtocolTy->setBody(ProtocolExtensionPtrTy, Int8PtrTy,
5905 ClassTy->setBody(llvm::PointerType::getUnqual(ClassTy),
5951 // specific. 18 is what's used on 32-bit X86.
6009 ProtocolListnfABITy->setBody(LongTy,
6057 // ImpnfABITy - LLVM for id (*)(id, SEL, ...)
6060 ->getPointerTo();
6071 ClassnfABITy->setBody(llvm::PointerType::getUnqual(ClassnfABITy),
6098 // MessageRefTy - LLVM for:
6108 RD->addDecl(FieldDecl::Create(Ctx, RD, SourceLocation(), SourceLocation(),
6111 RD->addDecl(FieldDecl::Create(Ctx, RD, SourceLocation(), SourceLocation(),
6114 RD->completeDefinition();
6120 // MessageRefPtrTy - LLVM for struct _message_ref_t*
6123 // SuperMessageRefTy - LLVM for:
6131 // SuperMessageRefPtrTy - LLVM for struct _super_message_ref_t*
6175 CGM.getModule(), Init->getType(), false,
6177 GV->setAlignment(CGM.getDataLayout().getABITypeAlign(Init->getType()));
6178 GV->setSection(SectionName);
6191 if (ObjCImplementationDecl *IMP = ID->getImplementation())
6193 if (ID->isWeakImported() && !IMP->isWeakImported()) {
6194 DefinedClasses[i]->setLinkage(llvm::GlobalVariable::ExternalLinkage);
6195 DefinedMetaClasses[i]->setLinkage(llvm::GlobalVariable::ExternalLinkage);
6222 /// isVTableDispatchedSelector - Returns true if SEL is not in the list of
6224 /// except for the 19 selectors in the list, we generate 32bit-style
6227 // At various points we've experimented with using vtable-based
6238 // If so, see whether this selector is in the white-list of things which must
6248 // These are vtable-based if GC is disabled.
6264 // These are vtable-based if GC is enabled.
6283 /// BuildClassRoTInitializer - generate meta-data for:
6303 std::string ClassName = std::string(ID->getObjCRuntimeNameAsString());
6323 values.add(GetClassName(ID->getObjCRuntimeNameAsString()));
6328 for (const auto *MD : ID->class_methods())
6329 if (!MD->isDirectMethod())
6332 for (const auto *MD : ID->instance_methods())
6333 if (!MD->isDirectMethod())
6337 values.add(emitMethodList(ID->getObjCRuntimeNameAsString(),
6343 const ObjCInterfaceDecl *OID = ID->getClassInterface();
6346 + OID->getObjCRuntimeNameAsString(),
6347 OID->all_referenced_protocol_begin(),
6348 OID->all_referenced_protocol_end()));
6354 "_OBJC_$_CLASS_PROP_LIST_" + ID->getObjCRuntimeNameAsString(),
6355 ID, ID->getClassInterface(), ObjCTypes, true));
6360 "_OBJC_$_PROP_LIST_" + ID->getObjCRuntimeNameAsString(),
6361 ID, ID->getClassInterface(), ObjCTypes, false));
6407 GV->setSection("__DATA, __objc_data");
6408 GV->setAlignment(CGM.getDataLayout().getABITypeAlign(ObjCTypes.ClassnfABITy));
6411 GV->setVisibility(llvm::GlobalValue::HiddenVisibility);
6417 return OD->getClassMethod(GetNullarySelector("load")) != nullptr ||
6418 OD->getClassInterface()->hasAttr<ObjCNonLazyClassAttr>() ||
6419 OD->hasAttr<ObjCNonLazyClassAttr>();
6445 for (const auto *Result : DC->lookup(&II))
6451 if (VD->hasAttr<DLLExportAttr>())
6453 if (VD->hasAttr<DLLImportAttr>())
6465 ObjCEmptyCacheVar->setDLLStorageClass(getStorage(CGM, "_objc_empty_cache"));
6476 llvm::ConstantPointerNull::get(ObjCTypes.ImpnfABITy->getPointerTo());
6487 const auto *CI = ID->getClassInterface();
6488 assert(CI && "CGObjCNonFragileABIMac::GenerateClass - class is 0");
6492 ? !CI->hasAttr<DLLExportAttr>()
6493 : CI->getVisibility() == HiddenVisibility;
6499 if (ID->hasNonZeroConstructors() || ID->hasDestructors()) {
6501 if (!ID->hasNonZeroConstructors())
6505 if (!CI->getSuperClass()) {
6513 const ObjCInterfaceDecl *Root = ID->getClassInterface();
6514 while (const ObjCInterfaceDecl *Super = Root->getSuperClass())
6517 const auto *Super = CI->getSuperClass();
6536 if (ID->hasNonZeroConstructors() || ID->hasDestructors()) {
6541 // anything except zero-initialization during construction. This
6543 // also imagine there being C++ types with non-trivial default
6545 if (!ID->hasNonZeroConstructors())
6552 if (!CI->getSuperClass()) {
6557 const auto *Super = CI->getSuperClass();
6572 // Determine if this class is also "non-lazy".
6579 // Make sure method definition entries are all clear for next implementation.
6583 /// GenerateProtocolRef - This routine is called to generate code for
6589 /// which will hold address of the protocol meta-data.
6595 // of protocol's meta-data (not a reference to it!)
6596 assert(!PD->isNonRuntimeProtocol() &&
6601 ProtocolName += PD->getObjCRuntimeNameAsString();
6607 return CGF.Builder.CreateAlignedLoad(PTGV->getValueType(), PTGV, Align);
6608 PTGV = new llvm::GlobalVariable(CGM.getModule(), Init->getType(), false,
6611 PTGV->setSection(GetSectionName("__objc_protorefs",
6613 PTGV->setVisibility(llvm::GlobalValue::HiddenVisibility);
6614 PTGV->setAlignment(Align.getAsAlign());
6616 PTGV->setComdat(CGM.getModule().getOrInsertComdat(ProtocolName));
6618 return CGF.Builder.CreateAlignedLoad(PTGV->getValueType(), PTGV, Align);
6621 /// GenerateCategory - Build metadata for a category implementation.
6634 const ObjCInterfaceDecl *Interface = OCD->getClassInterface();
6638 ExtCatName += Interface->getObjCRuntimeNameAsString();
6640 ExtCatName += OCD->getNameAsString();
6644 values.add(GetClassName(OCD->getIdentifier()->getName()));
6645 // meta-class entry symbol
6648 (Interface->getObjCRuntimeNameAsString() + "_$_" + OCD->getName()).str();
6652 for (const auto *MD : OCD->methods()) {
6653 if (MD->isDirectMethod())
6655 if (MD->isInstanceMethod()) {
6670 instanceMethodList->isNullValue() && classMethodList->isNullValue();
6673 Interface->FindCategoryDeclaration(OCD->getIdentifier());
6677 << Interface->getObjCRuntimeNameAsString() << "_$_" << OCD->getName();
6680 Interface->getObjCRuntimeNameAsString() + "_$_" +
6681 Category->getName(),
6682 Category->protocol_begin(), Category->protocol_end());
6691 isEmptyCategory &= protocolList->isNullValue() &&
6692 propertyList->isNullValue() &&
6693 classPropertyList->isNullValue();
6714 if (Interface->hasAttr<ObjCClassStubAttr>())
6719 // Determine if this category is also "non-lazy".
6722 // method definition entries must be clear for next implementation.
6726 /// emitMethodConstant - Return a struct objc_method constant. If
6728 /// the method must have a definition registered with the runtime.
6738 auto method = builder.beginStruct(ObjCTypes.MethodTy);
6739 method.add(GetMethodVarName(MD->getSelector()));
6740 method.add(GetMethodVarType(MD));
6743 // Protocol methods have no implementation. So, this entry is always NULL.
6744 method.addNullPointer(ObjCTypes.Int8PtrProgramASTy);
6747 assert(fn && "no definition for method?");
6748 method.add(fn);
6751 method.finishAndAddTo(builder);
6754 /// Build meta-data for method declarations.
6825 /// ObjCIvarOffsetVariable - Returns the ivar offset variable for
6830 const ObjCInterfaceDecl *Container = Ivar->getContainingInterface();
6832 Name += Container->getObjCRuntimeNameAsString();
6834 Name += Ivar->getName();
6843 Ivar->getAccessControl() == ObjCIvarDecl::Private ||
6844 Ivar->getAccessControl() == ObjCIvarDecl::Package;
6846 const ObjCInterfaceDecl *ContainingID = Ivar->getContainingInterface();
6848 if (ContainingID->hasAttr<DLLImportAttr>())
6850 ->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
6851 else if (ContainingID->hasAttr<DLLExportAttr>() && !IsPrivateOrPackage)
6853 ->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);
6864 IvarOffsetGV->setInitializer(
6866 IvarOffsetGV->setAlignment(
6872 if (Ivar->getAccessControl() == ObjCIvarDecl::Private ||
6873 Ivar->getAccessControl() == ObjCIvarDecl::Package ||
6874 ID->getVisibility() == HiddenVisibility)
6875 IvarOffsetGV->setVisibility(llvm::GlobalValue::HiddenVisibility);
6877 IvarOffsetGV->setVisibility(llvm::GlobalValue::DefaultVisibility);
6884 IvarOffsetGV->setConstant(true);
6887 IvarOffsetGV->setSection("__DATA, __objc_ivar");
6891 /// EmitIvarList - Emit the ivar list for the given
6918 const ObjCInterfaceDecl *OID = ID->getClassInterface();
6919 assert(OID && "CGObjCNonFragileABIMac::EmitIvarList - null interface");
6923 for (const ObjCIvarDecl *IVD = OID->all_declared_ivar_begin();
6924 IVD; IVD = IVD->getNextIvar()) {
6925 // Ignore unnamed bit-fields.
6926 if (!IVD->getDeclName())
6930 ivar.add(EmitIvarOffsetVar(ID->getClassInterface(), IVD,
6932 ivar.add(GetMethodVarName(IVD->getIdentifier()));
6935 CGM.getTypes().ConvertTypeForMem(IVD->getType());
6938 IVD->getType().getTypePtr()) >> 3;
6962 ivarList, Prefix + OID->getObjCRuntimeNameAsString(), CGM);
6969 llvm::GlobalVariable *&Entry = Protocols[PD->getIdentifier()];
6971 assert(!PD->isNonRuntimeProtocol() &&
6972 "attempting to GetOrEmit a non-runtime protocol");
6973 if (!Entry) {
6979 << PD->getObjCRuntimeNameAsString();
6981 Entry = new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ProtocolnfABITy,
6985 Entry->setComdat(CGM.getModule().getOrInsertComdat(Protocol));
6988 return Entry;
6991 /// GetOrEmitProtocol - Generate the protocol meta-data:
7013 llvm::GlobalVariable *Entry = Protocols[PD->getIdentifier()];
7016 if (Entry && Entry->hasInitializer())
7017 return Entry;
7020 assert(PD->hasDefinition() &&
7022 PD = PD->getDefinition();
7031 values.add(GetClassName(PD->getObjCRuntimeNameAsString()));
7033 + PD->getObjCRuntimeNameAsString(),
7034 PD->protocol_begin(),
7035 PD->protocol_end()));
7045 "_OBJC_$_PROP_LIST_" + PD->getObjCRuntimeNameAsString(),
7052 + PD->getObjCRuntimeNameAsString(),
7060 "_OBJC_$_CLASS_PROP_LIST_" + PD->getObjCRuntimeNameAsString(),
7063 if (Entry) {
7065 Entry->setLinkage(llvm::GlobalValue::WeakAnyLinkage);
7066 values.finishAndSetAsInitializer(Entry);
7070 << "_OBJC_PROTOCOL_$_" << PD->getObjCRuntimeNameAsString();
7072 Entry = values.finishAndCreateGlobal(symbolName, CGM.getPointerAlign(),
7076 Entry->setComdat(CGM.getModule().getOrInsertComdat(symbolName));
7078 Protocols[PD->getIdentifier()] = Entry;
7080 Entry->setVisibility(llvm::GlobalValue::HiddenVisibility);
7081 CGM.addUsedGlobal(Entry);
7083 // Use this protocol meta-data to build protocol list table in section
7087 << PD->getObjCRuntimeNameAsString();
7091 false, llvm::GlobalValue::WeakAnyLinkage, Entry,
7094 PTGV->setComdat(CGM.getModule().getOrInsertComdat(ProtocolRef));
7095 PTGV->setAlignment(
7097 PTGV->setSection(GetSectionName("__objc_protolist",
7099 PTGV->setVisibility(llvm::GlobalValue::HiddenVisibility);
7101 return Entry;
7104 /// EmitProtocolList - Generate protocol list meta-data:
7144 // A null-terminated array of protocols.
7159 /// EmitObjCValueForIvar - Code Gen for nonfragile ivar reference.
7171 ObjCInterfaceDecl *ID = ObjectTy->castAs<ObjCObjectType>()->getInterface();
7185 ComputeIvarBaseOffset(CGM, Interface->getImplementation(), Ivar));
7189 CGF.Builder.CreateAlignedLoad(GV->getValueType(), GV,
7193 ->setMetadata(llvm::LLVMContext::MD_invariant_load,
7219 /// Emit a "vtable" message send. We emit a weak hidden-visibility
7225 /// substitutes a stub function which simply tail-calls through the
7227 /// which tail-calls objc_msgSend. Both stubs adjust the selector
7238 const ObjCMethodDecl *method) {
7242 // First argument: the receiver / super-call structure.
7253 MessageSendInfo MSI = getMessageSendInfo(method, resultType, args);
7262 // except normal, non-super message-sends.
7306 messageRef->setVisibility(llvm::GlobalValue::HiddenVisibility);
7307 messageRef->setSection(GetSectionName("__objc_msgrefs", "coalesced"));
7311 if (CGM.getLangOpts().ObjCAutoRefCount && method)
7312 for (const auto *ParamDecl : method->parameters()) {
7313 if (ParamDecl->isDestroyedInCallee()) {
7337 requiresnullCheck ? method : nullptr);
7349 const ObjCMethodDecl *Method) {
7353 false, CallArgs, Method)
7356 false, CallArgs, Method, Class, ObjCTypes);
7365 return GetClassGlobal((prefix + ID->getObjCRuntimeNameAsString()).str(),
7367 ID->isWeakImported(),
7370 && ID->hasAttr<DLLImportAttr>());
7382 if (!GV || GV->getValueType() != ObjCTypes.ClassnfABITy) {
7387 NewGV->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
7390 GV->replaceAllUsesWith(NewGV);
7391 GV->eraseFromParent();
7397 assert(GV->getLinkage() == L);
7406 if (!ID->hasAttr<ObjCClassStubAttr>())
7411 // Stub classes are pointer-aligned. Classrefs pointing at stub classes
7420 llvm::GlobalVariable *Entry) {
7421 if (ID && ID->hasAttr<ObjCClassStubAttr>()) {
7422 // Classrefs pointing at Objective-C stub classes must be loaded by calling
7425 ObjCTypes.getLoadClassrefFn(), Entry, "load_classref_result");
7429 return CGF.Builder.CreateAlignedLoad(Entry->getValueType(), Entry, Align);
7436 llvm::GlobalVariable *&Entry = ClassReferences[II];
7438 if (!Entry) {
7443 ClassGV = GetClassGlobal((getClassSymbolPrefix() + II->getName()).str(),
7445 assert(ClassGV->getType() == ObjCTypes.ClassnfABIPtrTy &&
7451 Entry = new llvm::GlobalVariable(
7452 CGM.getModule(), ClassGV->getType(), false,
7455 Entry->setAlignment(CGF.getPointerAlign().getAsAlign());
7456 if (!ID || !ID->hasAttr<ObjCClassStubAttr>())
7457 Entry->setSection(SectionName);
7459 CGM.addCompilerUsedGlobal(Entry);
7462 return EmitLoadOfClassRef(CGF, ID, Entry);
7468 // use the Objective-C runtime to get the class.
7469 if (ID->hasAttr<ObjCRuntimeVisibleAttr>())
7472 return EmitClassRefFromId(CGF, ID->getIdentifier(), ID);
7484 llvm::GlobalVariable *&Entry = SuperClassReferences[ID->getIdentifier()];
7486 if (!Entry) {
7490 Entry = new llvm::GlobalVariable(CGM.getModule(), ClassGV->getType(), false,
7493 Entry->setAlignment(CGF.getPointerAlign().getAsAlign());
7494 Entry->setSection(SectionName);
7495 CGM.addCompilerUsedGlobal(Entry);
7498 return EmitLoadOfClassRef(CGF, ID, Entry);
7501 /// EmitMetaClassRef - Return a Value * of the address of _class_t
7502 /// meta-data
7508 llvm::GlobalVariable * &Entry = MetaClassReferences[ID->getIdentifier()];
7509 if (!Entry) {
7513 Entry = new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ClassnfABIPtrTy,
7516 Entry->setAlignment(Align.getAsAlign());
7517 Entry->setSection(SectionName);
7518 CGM.addCompilerUsedGlobal(Entry);
7521 return CGF.Builder.CreateAlignedLoad(ObjCTypes.ClassnfABIPtrTy, Entry, Align);
7524 /// GetClass - Return a reference to the class for the given interface
7528 if (ID->isWeakImported()) {
7532 cast<llvm::GlobalVariable>(ClassGV)->hasExternalWeakLinkage());
7540 /// which class's method should be called.
7551 const ObjCMethodDecl *Method) {
7566 Target = EmitMetaClassRef(CGF, Class, Class->isWeakImported());
7580 true, CallArgs, Method)
7583 true, CallArgs, Method, Class, ObjCTypes);
7591 LI->setMetadata(llvm::LLVMContext::MD_invariant_load,
7597 llvm::GlobalVariable *&Entry = SelectorReferences[Sel];
7599 if (!Entry) {
7602 Entry = new llvm::GlobalVariable(
7606 Entry->setExternallyInitialized(true);
7607 Entry->setSection(SectionName);
7608 Entry->setAlignment(Align.getAsAlign());
7609 CGM.addCompilerUsedGlobal(Entry);
7612 return ConstantAddress(Entry, ObjCTypes.SelectorPtrTy, Align);
7615 /// EmitObjCIvarAssign - Code gen for assigning to a __strong object.
7622 llvm::Type * SrcTy = src->getType();
7637 /// EmitObjCStrongCastAssign - Code gen for assigning to a __strong cast object.
7643 llvm::Type * SrcTy = src->getType();
7667 /// EmitObjCWeakRead - Code gen for loading value of a __weak
7683 /// EmitObjCWeakAssign - Code gen for assigning to a __weak object.
7688 llvm::Type * SrcTy = src->getType();
7704 /// EmitObjCGlobalAssign - Code gen for assigning to a __strong object.
7710 llvm::Type * SrcTy = src->getType();
7740 if (T->isObjCIdType() || T->isObjCQualifiedIdType()) {
7748 IDEHType->setDLLStorageClass(getStorage(CGM, "OBJC_EHTYPE_id"));
7753 // All other types should be Objective-C interface pointer types.
7754 const ObjCObjectPointerType *PT = T->getAs<ObjCObjectPointerType>();
7757 const ObjCInterfaceType *IT = PT->getInterfaceType();
7760 return GetInterfaceEHType(IT->getDecl(), NotForDefinition);
7770 /// EmitThrowStmt - Generate code for a throw statement.
7779 Call->setDoesNotReturn();
7783 Call->setDoesNotReturn();
7794 llvm::GlobalVariable * &Entry = EHTypeReferences[ID->getIdentifier()];
7795 StringRef ClassName = ID->getObjCRuntimeNameAsString();
7797 // If we don't need a definition, return the entry if found or check
7800 if (Entry)
7801 return Entry;
7807 Entry = new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.EHTypeTy,
7810 CGM.setGVProperties(Entry, ID);
7811 return Entry;
7815 // Otherwise we need to either make a new entry or fill in the initializer.
7816 assert((!Entry || !Entry->hasInitializer()) && "Duplicate EHType definition");
7826 VTableGV->setDLLStorageClass(getStorage(CGM, VTableName));
7833 llvm::ConstantExpr::getInBoundsGetElementPtr(VTableGV->getValueType(),
7841 if (Entry) {
7842 values.finishAndSetAsInitializer(Entry);
7843 Entry->setAlignment(CGM.getPointerAlign().getAsAlign());
7845 Entry = values.finishAndCreateGlobal("OBJC_EHTYPE_$_" + ClassName,
7850 CGM.setGVProperties(Entry, ID);
7852 assert(Entry->getLinkage() == L);
7855 if (ID->getVisibility() == HiddenVisibility)
7856 Entry->setVisibility(llvm::GlobalValue::HiddenVisibility);
7860 Entry->setSection("__DATA,__objc_const");
7862 return Entry;