Lines Matching +full:bool +full:- +full:property

1 //===--- SemaObjCProperty.cpp - Semantic Analysis for ObjC @property ------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements semantic analysis for Objective C @property and
12 //===----------------------------------------------------------------------===//
29 //===----------------------------------------------------------------------===//
31 //===----------------------------------------------------------------------===//
33 /// getImpliedARCOwnership - Given a set of property attributes and a
54 // property type.
56 type->isObjCRetainableType()) {
63 /// Check the internal consistency of a property declaration with
66 ObjCPropertyDecl *property) {
67 if (property->isInvalidDecl()) return;
69 ObjCPropertyAttribute::Kind propertyKind = property->getPropertyAttributes();
71 = property->getType().getObjCLifetime();
76 = getImpliedARCOwnership(propertyKind, property->getType());
78 // We have a lifetime qualifier but no dominating property
80 // setting the property attribute according to the lifetime
91 property->setPropertyAttributes(attr);
97 property->setInvalidDecl();
98 S.Diag(property->getLocation(),
100 << property->getDeclName()
105 /// Check this Objective-C property against a property declared in the
115 // Look for a property with the same name.
116 if (ObjCPropertyDecl *ProtoProp = Proto->getProperty(
117 Prop->getIdentifier(), Prop->isInstanceProperty())) {
118 S.ObjC().DiagnosePropertyMismatch(Prop, ProtoProp, Proto->getIdentifier(),
123 // Check this property against any protocols we inherit.
124 for (auto *P : Proto->protocols())
184 QualType T = TSI->getType();
188 bool isReadWrite = ((Attributes & ObjCPropertyAttribute::kind_readwrite) ||
196 if (CDecl->IsClassExtension()) {
216 Res->setLexicalDeclContext(lexicalDC);
219 // Validate the attributes on the @property.
225 if (Res->getType().getObjCLifetime())
230 // For a class, compare the property against a property in our superclass.
231 bool FoundInSuper = false;
233 while (ObjCInterfaceDecl *Super = CurrentInterfaceDecl->getSuperClass()) {
234 if (ObjCPropertyDecl *SuperProp = Super->getProperty(
235 Res->getIdentifier(), Res->isInstanceProperty())) {
236 DiagnosePropertyMismatch(Res, SuperProp, Super->getIdentifier(), false);
244 // Also compare the property against a property in our protocols.
245 for (auto *P : CurrentInterfaceDecl->protocols()) {
250 for (auto *P : IFace->all_referenced_protocols()) {
257 // when property in class extension is constructed.
258 if (!Cat->IsClassExtension())
259 for (auto *P : Cat->protocols())
263 for (auto *P : Proto->protocols())
306 static bool LocPropertyAttribute( ASTContext &Context, const char *attrName,
314 bool invalidTemp = false;
339 bool PropagateAtomicity) {
341 bool OldIsAtomic = (OldProperty->getPropertyAttributes() &
343 bool NewIsAtomic = (NewProperty->getPropertyAttributes() &
347 // Determine whether the given property is readonly and implicitly
349 auto isImplicitlyReadonlyAtomic = [](ObjCPropertyDecl *Property) -> bool {
351 auto Attrs = Property->getPropertyAttributes();
360 if (Property->getPropertyAttributesAsWritten() &
367 // If we're allowed to propagate atomicity, and the new property did
372 ((NewProperty->getPropertyAttributesAsWritten() & AtomicityMask) == 0)) {
373 unsigned Attrs = NewProperty->getPropertyAttributes();
380 NewProperty->overwritePropertyAttributes(Attrs);
384 // One of the properties is atomic; if it's a readonly property, and
392 auto *OldDC = OldProperty->getDeclContext();
394 OldContextName = Category->getClassInterface()->getIdentifier();
396 OldContextName = cast<ObjCContainerDecl>(OldDC)->getIdentifier();
398 S.Diag(NewProperty->getLocation(), diag::warn_property_attribute)
399 << NewProperty->getDeclName() << "atomic"
401 S.Diag(OldProperty->getLocation(), diag::note_property_declare);
407 Selector SetterSel, SourceLocation SetterNameLoc, const bool isReadWrite,
411 // Diagnose if this property is already in continuation class.
414 ObjCInterfaceDecl *CCPrimary = CDecl->getClassInterface();
416 // We need to look in the @interface to see if the @property was
419 Diag(CDecl->getLocation(), diag::err_continuation_class);
423 bool isClassProperty =
427 // Find the property in the extended class's primary class or
429 ObjCPropertyDecl *PIDecl = CCPrimary->FindPropertyVisibleInPrimaryClass(
432 // If we found a property in an extension, complain.
433 if (PIDecl && isa<ObjCCategoryDecl>(PIDecl->getDeclContext())) {
435 Diag(PIDecl->getLocation(), diag::note_property_declare);
441 // A readonly property declared in the primary class can be refined
442 // by adding a readwrite property within an extension.
444 if (!(PIDecl->isReadOnly() && isReadWrite)) {
446 // property is declared both in the @interface and the continuation.
451 (PIDecl->getPropertyAttributesAsWritten() &
456 << CCPrimary->getDeclName();
457 Diag(PIDecl->getLocation(), diag::note_property_declare);
462 if (PIDecl->getGetterName() != GetterSel) {
466 << PIDecl->getGetterName() << GetterSel;
467 Diag(PIDecl->getLocation(), diag::note_property_declare);
471 GetterSel = PIDecl->getGetterName();
477 = getOwnershipRule(PIDecl->getPropertyAttributes());
483 Diag(PIDecl->getLocation(), diag::note_property_declare);
486 // Take the ownership from the original property.
490 // If the redeclaration is 'weak' but the original property is not,
492 !(PIDecl->getPropertyAttributesAsWritten() &
494 PIDecl->getType()->getAs<ObjCObjectPointerType>() &&
495 PIDecl->getType().getObjCLifetime() == Qualifiers::OCL_None) {
497 Diag(PIDecl->getLocation(), diag::note_property_declare);
510 // If there was no declaration of a property with the same name in
517 if (!Context.hasSameType(PIDecl->getType(), PDecl->getType())) {
518 bool IncompatibleObjC = false;
520 // Relax the strict type matching for property type in continuation class.
521 // Allow property object type of continuation class to be different as long
522 // as it narrows the object type in its primary class property. Note that
524 // property in primary class and 'narrowed' type for a 'readwrite' property
526 QualType PrimaryClassPropertyT = Context.getCanonicalType(PIDecl->getType());
527 QualType ClassExtPropertyT = Context.getCanonicalType(PDecl->getType());
535 diag::err_type_mismatch_continuation_class) << PDecl->getType();
536 Diag(PIDecl->getLocation(), diag::note_property_declare);
541 // Check that atomicity of property in class extension matches the previous
554 SourceLocation SetterNameLoc, const bool isReadWrite,
561 // Property defaults to 'assign' if it is readwrite, unless this is ARC
563 bool isAssign;
571 !T->isObjCRetainableType());
574 // Issue a warning if property is 'assign' as default and its
579 T->getAs<ObjCObjectPointerType>()) {
580 ObjCInterfaceDecl *IDecl = ObjPtrTy->getObjectType()->getInterface();
584 if (IDecl->ClassImplementsProtocol(PNSCopying, true))
589 if (T->isObjCObjectType()) {
590 SourceLocation StarLoc = TInfo->getTypeLoc().getEndLoc();
595 SourceLocation TLoc = TInfo->getTypeLoc().getBeginLoc();
605 bool isClassProperty =
608 // Class property and instance property can have the same name.
611 Diag(PDecl->getLocation(), diag::err_duplicate_property);
612 Diag(prevDecl->getLocation(), diag::note_property_declare);
613 PDecl->setInvalidDecl();
616 DC->addDecl(PDecl);
618 PDecl->setLexicalDeclContext(lexicalDC);
621 if (T->isArrayType() || T->isFunctionType()) {
623 PDecl->setInvalidDecl();
628 PDecl->setGetterName(GetterSel, GetterNameLoc);
629 PDecl->setSetterName(SetterSel, SetterNameLoc);
630 PDecl->setPropertyAttributesAsWritten(
636 PDecl->setPropertyAttributes(ObjCPropertyAttribute::kind_readonly);
639 PDecl->setPropertyAttributes(ObjCPropertyAttribute::kind_getter);
642 PDecl->setPropertyAttributes(ObjCPropertyAttribute::kind_setter);
645 PDecl->setPropertyAttributes(ObjCPropertyAttribute::kind_readwrite);
648 PDecl->setPropertyAttributes(ObjCPropertyAttribute::kind_retain);
651 PDecl->setPropertyAttributes(ObjCPropertyAttribute::kind_strong);
654 PDecl->setPropertyAttributes(ObjCPropertyAttribute::kind_weak);
657 PDecl->setPropertyAttributes(ObjCPropertyAttribute::kind_copy);
660 PDecl->setPropertyAttributes(ObjCPropertyAttribute::kind_unsafe_unretained);
663 PDecl->setPropertyAttributes(ObjCPropertyAttribute::kind_assign);
667 PDecl->setPropertyAttributes(ObjCPropertyAttribute::kind_nonatomic);
669 PDecl->setPropertyAttributes(ObjCPropertyAttribute::kind_atomic);
673 PDecl->setPropertyAttributes(ObjCPropertyAttribute::kind_assign);
675 PDecl->setPropertyAttributes(ObjCPropertyAttribute::kind_unsafe_unretained);
678 PDecl->setPropertyImplementation(ObjCPropertyDecl::Required);
680 PDecl->setPropertyImplementation(ObjCPropertyDecl::Optional);
683 PDecl->setPropertyAttributes(ObjCPropertyAttribute::kind_nullability);
686 PDecl->setPropertyAttributes(ObjCPropertyAttribute::kind_null_resettable);
689 PDecl->setPropertyAttributes(ObjCPropertyAttribute::kind_class);
692 CDecl->hasAttr<ObjCDirectMembersAttr>()) {
694 Diag(PDecl->getLocation(), diag::err_objc_direct_on_protocol) << true;
696 PDecl->setPropertyAttributes(ObjCPropertyAttribute::kind_direct);
698 Diag(PDecl->getLocation(), diag::warn_objc_direct_property_ignored)
699 << PDecl->getDeclName();
707 ObjCPropertyDecl *property,
709 if (property->isInvalidDecl() || ivar->isInvalidDecl()) return;
711 QualType ivarType = ivar->getType();
714 // The lifetime implied by the property's attributes.
716 getImpliedARCOwnership(property->getPropertyAttributes(),
717 property->getType());
732 // property implementation before parsing any method bodies.
735 ivar->getAccessControl() == ObjCIvarDecl::Private) {
738 assert(ivarType->isObjCARCImplicitlyUnretainedType());
741 ivar->setType(ivarType);
748 S.Diag(ivar->getLocation(), diag::err_arc_strong_property_ownership)
749 << property->getDeclName()
750 << ivar->getDeclName()
755 S.Diag(ivar->getLocation(), diag::err_weak_property)
756 << property->getDeclName()
757 << ivar->getDeclName();
761 S.Diag(ivar->getLocation(), diag::err_arc_assign_property_ownership)
762 << property->getDeclName() << ivar->getDeclName()
763 << ((property->getPropertyAttributesAsWritten() &
771 // Any other property should be ignored.
775 S.Diag(property->getLocation(), diag::note_property_declare);
780 /// setImpliedPropertyAttributeForReadOnlyProperty -
781 /// This routine evaludates life-time attributes for a 'readonly'
782 /// property with no known lifetime of its own, using backing
783 /// 'ivar's attribute, if any. If no backing 'ivar', property's
784 /// life-time is assumed 'strong'.
786 ObjCPropertyDecl *property, ObjCIvarDecl *ivar) {
788 getImpliedARCOwnership(property->getPropertyAttributes(),
789 property->getType());
794 // if no backing ivar, make property 'strong'.
795 property->setPropertyAttributes(ObjCPropertyAttribute::kind_strong);
798 // property assumes owenership of backing ivar.
799 QualType ivarType = ivar->getType();
802 property->setPropertyAttributes(ObjCPropertyAttribute::kind_strong);
804 property->setPropertyAttributes(ObjCPropertyAttribute::kind_weak);
807 static bool isIncompatiblePropertyAttribute(unsigned Attr1, unsigned Attr2,
812 static bool areIncompatiblePropertyAttributes(unsigned Attr1, unsigned Attr2,
817 /// SelectPropertyForSynthesisFromProtocols - Finds the most appropriate
818 /// property declaration that should be synthesised in all of the inherited
825 ObjCPropertyDecl *Property) {
826 assert(isa<ObjCProtocolDecl>(Property->getDeclContext()) &&
827 "Expected a property from a protocol");
830 for (const auto *PI : ClassDecl->all_referenced_protocols()) {
831 if (const ObjCProtocolDecl *PDecl = PI->getDefinition())
832 PDecl->collectInheritedProtocolProperties(Property, ProtocolSet,
835 if (ObjCInterfaceDecl *SDecl = ClassDecl->getSuperClass()) {
837 for (const auto *PI : SDecl->all_referenced_protocols()) {
838 if (const ObjCProtocolDecl *PDecl = PI->getDefinition())
839 PDecl->collectInheritedProtocolProperties(Property, ProtocolSet,
842 SDecl = SDecl->getSuperClass();
847 return Property;
849 ObjCPropertyDecl *OriginalProperty = Property;
852 // Select the 'readwrite' property if such property exists.
853 if (Property->isReadOnly() && !Prop.value()->isReadOnly()) {
854 Property = Prop.value();
858 if (Property != OriginalProperty) {
859 // Check that the old property is compatible with the new one.
863 QualType RHSType = S.Context.getCanonicalType(Property->getType());
864 unsigned OriginalAttributes = Property->getPropertyAttributesAsWritten();
872 // Represents a property from another protocol that conflicts with the
881 // Verify the property attributes.
882 unsigned Attr = Prop->getPropertyAttributesAsWritten();
884 auto Diag = [&](bool OriginalHasAttribute, StringRef AttributeName) {
889 // The ownership might be incompatible unless the property has no explicit
891 bool HasOwnership =
919 if (Property->getGetterName() != Prop->getGetterName()) {
923 if (!Property->isReadOnly() && !Prop->isReadOnly() &&
924 Property->getSetterName() != Prop->getSetterName()) {
928 QualType LHSType = S.Context.getCanonicalType(Prop->getType());
930 bool IncompatibleObjC = false;
941 return Property;
945 bool HasIncompatibleAttributes = false;
951 auto Diag = S.Diag(Property->getLocation(),
952 Property != OriginalProperty || HasIncompatibleAttributes
958 Diag << Property->getType();
965 Diag << Property->getGetterName();
968 Diag << Property->getSetterName();
974 S.Diag(Note.Prop->getLocation(), diag::note_protocol_property_declare)
978 Diag << Note.Prop->getType();
985 Diag << Note.Prop->getGetterName();
988 Diag << Note.Prop->getSetterName();
995 return Property;
998 /// Determine whether any storage attributes were written on the property.
999 static bool hasWrittenStorageAttribute(ObjCPropertyDecl *Prop,
1001 if (Prop->getPropertyAttributesAsWritten() & OwnershipMask) return true;
1003 // If this is a readwrite property in a class extension that refines
1004 // a readonly property in the original class definition, check it as
1007 // If it's a readonly property, we're not interested.
1008 if (Prop->isReadOnly()) return false;
1011 auto Category = dyn_cast<ObjCCategoryDecl>(Prop->getDeclContext());
1012 if (!Category || !Category->IsClassExtension()) return false;
1014 // Find the corresponding property in the primary class definition.
1015 auto OrigClass = Category->getClassInterface();
1016 for (auto *Found : OrigClass->lookup(Prop->getDeclName())) {
1018 return OrigProp->getPropertyAttributesAsWritten() & OwnershipMask;
1022 for (const auto *Proto : OrigClass->all_referenced_protocols()) {
1023 if (ObjCPropertyDecl *OrigProp = Proto->FindPropertyDeclaration(
1024 Prop->getIdentifier(), QueryKind))
1025 return OrigProp->getPropertyAttributesAsWritten() & OwnershipMask;
1031 /// Create a synthesized property accessor stub inside the \@implementation.
1038 Context, AtLoc.isValid() ? AtLoc : Decl->getBeginLoc(),
1039 PropertyLoc.isValid() ? PropertyLoc : Decl->getEndLoc(),
1040 Decl->getSelector(), Decl->getReturnType(),
1041 Decl->getReturnTypeSourceInfo(), Impl, Decl->isInstanceMethod(),
1042 Decl->isVariadic(), Decl->isPropertyAccessor(),
1043 /* isSynthesized*/ true, Decl->isImplicit(), Decl->isDefined(),
1044 Decl->getImplementationControl(), Decl->hasRelatedResultType());
1045 ImplDecl->getMethodFamily();
1046 if (Decl->hasAttrs())
1047 ImplDecl->setAttrs(Decl->getAttrs());
1048 ImplDecl->setSelfDecl(Decl->getSelfDecl());
1049 ImplDecl->setCmdDecl(Decl->getCmdDecl());
1051 Decl->getSelectorLocs(SelLocs);
1052 ImplDecl->setMethodParams(Context, Decl->parameters(), SelLocs);
1053 ImplDecl->setLexicalDeclContext(Impl);
1054 ImplDecl->setDefined(false);
1058 /// ActOnPropertyImplDecl - This routine performs semantic checks and
1059 /// builds the AST node for a property implementation declaration; declared
1063 Scope *S, SourceLocation AtLoc, SourceLocation PropertyLoc, bool Synthesize,
1069 // Make sure we have a context for the property implementation declaration.
1078 PropertyDiagLoc = ClassImpDecl->getBeginLoc();
1079 ObjCPropertyDecl *property = nullptr;
1081 // Find the class or category class where this property must have
1086 IDecl = IC->getClassInterface();
1088 // without an interface decl. So, IDecl is always non-zero.
1090 "ActOnPropertyImplDecl - @implementation without @interface");
1092 // Look for this property declaration in the @implementation's @interface
1093 property = IDecl->FindPropertyDeclaration(PropertyId, QueryKind);
1094 if (!property) {
1095 Diag(PropertyLoc, diag::err_bad_property_decl) << IDecl->getDeclName();
1098 if (property->isClassProperty() && Synthesize) {
1102 unsigned PIkind = property->getPropertyAttributesAsWritten();
1108 Diag(IC->getLocation(), diag::warn_auto_implicit_atomic_property);
1109 Diag(property->getLocation(), diag::note_property_declare);
1113 dyn_cast<ObjCCategoryDecl>(property->getDeclContext())) {
1114 if (!CD->IsClassExtension()) {
1115 Diag(PropertyLoc, diag::err_category_property) << CD->getDeclName();
1116 Diag(property->getLocation(), diag::note_property_declare);
1121 property->hasAttr<IBOutletAttr>() && !AtLoc.isValid()) {
1122 bool ReadWriteProperty = false;
1123 // Search into the class extensions and see if 'readonly property is
1125 for (auto *Ext : IDecl->known_extensions()) {
1126 DeclContext::lookup_result R = Ext->lookup(property->getDeclName());
1128 PIkind = ExtProp->getPropertyAttributesAsWritten();
1137 Diag(property->getLocation(), diag::warn_auto_readonly_iboutlet_property)
1138 << property;
1141 property->getLParenLoc(), readonlyLoc)) {
1143 readonlyLoc.getLocWithOffset(strlen("readonly")-1);
1145 Diag(property->getLocation(),
1151 if (Synthesize && isa<ObjCProtocolDecl>(property->getDeclContext()))
1152 property = SelectPropertyForSynthesisFromProtocols(SemaRef, AtLoc, IDecl,
1153 property);
1160 IDecl = CatImplClass->getClassInterface();
1166 IDecl->FindCategoryDeclaration(CatImplClass->getIdentifier());
1172 // Look for this property declaration in @implementation's category
1173 property = Category->FindPropertyDeclaration(PropertyId, QueryKind);
1174 if (!property) {
1176 << Category->getDeclName();
1184 bool CompleteTypeErr = false;
1185 bool compat = true;
1193 Ivar = IDecl->lookupInstanceVariable(PropertyIvar, ClassDeclared);
1194 QualType PropType = property->getType();
1199 property->getDeclName())) {
1200 Diag(property->getLocation(), diag::note_property_declare);
1205 (property->getPropertyAttributesAsWritten() &
1207 PropertyIvarType->isObjCRetainableType()) {
1208 setImpliedPropertyAttributeForReadOnlyProperty(property, Ivar);
1211 ObjCPropertyAttribute::Kind kind = property->getPropertyAttributes();
1213 bool isARCWeak = false;
1215 // Add GC __weak to the ivar type if the property is weak.
1220 Diag(property->getLocation(), diag::note_property_declare);
1227 // the property type.
1236 Diag(property->getLocation(), diag::note_property_declare);
1242 PropertyIvarType->getAs<ObjCObjectPointerType>()) {
1243 const ObjCInterfaceDecl *ObjI = ObjT->getInterfaceDecl();
1244 if (ObjI && ObjI->isArcWeakrefUnavailable()) {
1245 Diag(property->getLocation(),
1248 Diag(ClassImpDecl->getLocation(), diag::note_implemented_by_class)
1249 << ClassImpDecl->getName();
1257 // Check when default synthesizing a property that there is
1258 // an ivar matching property name and issue warning; since this
1260 // property in non-default synthesis case.
1263 IDecl->lookupInstanceVariable(property->getIdentifier(),
1269 << originalIvar->getIdentifier();
1270 Diag(property->getLocation(), diag::note_property_declare);
1271 Diag(originalIvar->getLocation(), diag::note_ivar_decl);
1277 // property attributes.
1280 PropertyIvarType->isObjCRetainableType()) {
1283 // explicitly write an ownership attribute on the property.
1284 if (!hasWrittenStorageAttribute(property, QueryKind) &&
1288 Diag(property->getLocation(), diag::note_property_declare);
1292 assert(lifetime && "no lifetime for property?");
1308 Diag(property->getLocation(), diag::note_property_declare);
1313 const RecordType *RecordTy = PropertyIvarType->getAs<RecordType>();
1314 if (RecordTy && RecordTy->getDecl()->hasFlexibleArrayMember()) {
1321 Ivar->setInvalidDecl();
1322 ClassImpDecl->addDecl(Ivar);
1323 IDecl->makeDeclVisibleInContext(Ivar);
1329 // a property implementation and to avoid future warnings.
1333 << property->getDeclName() << Ivar->getDeclName()
1334 << ClassDeclared->getDeclName();
1335 Diag(Ivar->getLocation(), diag::note_previous_access_declaration)
1336 << Ivar << Ivar->getName();
1339 property->setPropertyIvarDecl(Ivar);
1341 QualType IvarType = Context.getCanonicalType(Ivar->getType());
1343 // Check that type of property and its ivar are type compatible.
1348 PropertyIvarType->castAs<ObjCObjectPointerType>(),
1349 IvarType->castAs<ObjCObjectPointerType>());
1357 << property->getDeclName() << PropType
1358 << Ivar->getDeclName() << IvarType;
1359 Diag(Ivar->getLocation(), diag::note_ivar_decl);
1361 // a property implementation and to avoid future warnings.
1366 // specifically for property redeclarations as well as for ivars.
1370 lhsType->isArithmeticType()) {
1372 << property->getDeclName() << PropType
1373 << Ivar->getDeclName() << IvarType;
1374 Diag(Ivar->getLocation(), diag::note_ivar_decl);
1375 // Fall thru - see previous comment
1382 << property->getDeclName() << Ivar->getDeclName();
1383 Diag(Ivar->getLocation(), diag::note_ivar_decl);
1384 // Fall thru - see previous comment
1386 // Fall thru - see previous comment
1387 if ((property->getType()->isObjCObjectPointerType() ||
1391 << property->getDeclName() << Ivar->getDeclName();
1392 // Fall thru - see previous comment
1396 Ivar->getType().getObjCLifetime())
1397 checkARCPropertyImpl(SemaRef, PropertyLoc, property, Ivar);
1402 assert (property && "ActOnPropertyImplDecl - property declaration missing");
1404 Context, SemaRef.CurContext, AtLoc, PropertyLoc, property,
1410 PIDecl->setInvalidDecl();
1412 if (ObjCMethodDecl *getterMethod = property->getGetterMethodDecl()) {
1413 getterMethod->createImplicitParams(Context, IDecl);
1418 ObjCMethodDecl *OMD = ClassImpDecl->getMethod(
1419 getterMethod->getSelector(), getterMethod->isInstanceMethod());
1423 PIDecl->setGetterMethodDecl(OMD);
1427 Ivar->getType()->isRecordType()) {
1428 // For Objective-C++, need to synthesize the AST for the IVAR object to be
1429 // returned by the getter as it must conform to C++'s copy-return rules.
1430 // FIXME. Eventually we want to do this for Objective-C as well.
1432 ImplicitParamDecl *SelfDecl = getterMethod->getSelfDecl();
1434 DeclRefExpr(Context, SelfDecl, false, SelfDecl->getType(), VK_LValue,
1438 Context, SelfDecl->getType(), CK_LValueToRValue, SelfExpr, nullptr,
1442 Ivar->getUsageType(SelfDecl->getType()),
1444 Ivar->getLocation(),
1448 getterMethod->getReturnType()),
1454 PIDecl->setGetterCXXConstructor(ResExpr);
1457 if (property->hasAttr<NSReturnsNotRetainedAttr>() &&
1458 !getterMethod->hasAttr<NSReturnsNotRetainedAttr>()) {
1459 Diag(getterMethod->getLocation(),
1461 Diag(property->getLocation(), diag::note_property_declare);
1464 switch (getterMethod->getMethodFamily()) {
1469 Diag(getterMethod->getLocation(), diag::err_arc_illegal_method_def)
1470 << 1 << getterMethod->getSelector();
1477 if (ObjCMethodDecl *setterMethod = property->getSetterMethodDecl()) {
1478 setterMethod->createImplicitParams(Context, IDecl);
1482 ObjCMethodDecl *OMD = ClassImpDecl->getMethod(
1483 setterMethod->getSelector(), setterMethod->isInstanceMethod());
1487 PIDecl->setSetterMethodDecl(OMD);
1491 Ivar->getType()->isRecordType()) {
1492 // FIXME. Eventually we want to do this for Objective-C as well.
1494 ImplicitParamDecl *SelfDecl = setterMethod->getSelfDecl();
1496 DeclRefExpr(Context, SelfDecl, false, SelfDecl->getType(), VK_LValue,
1500 Context, SelfDecl->getType(), CK_LValueToRValue, SelfExpr, nullptr,
1504 Ivar->getUsageType(SelfDecl->getType()),
1506 Ivar->getLocation(),
1508 ObjCMethodDecl::param_iterator P = setterMethod->param_begin();
1510 QualType T = Param->getType().getNonReferenceType();
1516 if (property->getPropertyAttributes() &
1521 if (const FunctionDecl *FuncDecl = CXXCE->getDirectCallee())
1522 if (!FuncDecl->isTrivial())
1523 if (property->getType()->isReferenceType()) {
1526 << property->getType();
1527 Diag(FuncDecl->getBeginLoc(), diag::note_callee_decl)
1531 PIDecl->setSetterCXXAssignment(Res.getAs<Expr>());
1538 IC->FindPropertyImplIvarDecl(PropertyIvar)) {
1540 << PropertyId << PPIDecl->getPropertyDecl()->getIdentifier()
1542 Diag(PPIDecl->getLocation(), diag::note_previous_use);
1546 = IC->FindPropertyImplDecl(PropertyId, QueryKind)) {
1548 Diag(PPIDecl->getLocation(), diag::note_previous_declaration);
1551 IC->addPropertyImplementation(PIDecl);
1554 !IDecl->isObjCRequiresPropertyDefs()) {
1556 // use and if 1) property is @dynamic or 2) property is synthesized
1561 Ivar = IDecl->lookupInstanceVariable(PropertyId, ClassDeclared);
1564 Ivar = IDecl->lookupInstanceVariable(PropertyId, ClassDeclared);
1567 if (Ivar && Ivar->getSynthesize() &&
1568 declaresSameEntity(IC->getClassInterface(), ClassDeclared)) {
1569 Diag(Ivar->getLocation(), diag::err_undeclared_var_use)
1571 Ivar->setInvalidDecl();
1577 CatImplClass->FindPropertyImplIvarDecl(PropertyIvar)) {
1579 << PropertyId << PPIDecl->getPropertyDecl()->getIdentifier()
1581 Diag(PPIDecl->getLocation(), diag::note_previous_use);
1585 CatImplClass->FindPropertyImplDecl(PropertyId, QueryKind)) {
1587 Diag(PPIDecl->getLocation(), diag::note_previous_declaration);
1590 CatImplClass->addPropertyImplementation(PIDecl);
1593 if (PIDecl->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic &&
1594 PIDecl->getPropertyDecl() &&
1595 PIDecl->getPropertyDecl()->isDirectProperty()) {
1597 Diag(PIDecl->getPropertyDecl()->getLocation(),
1605 //===----------------------------------------------------------------------===//
1607 //===----------------------------------------------------------------------===//
1609 /// DiagnosePropertyMismatch - Compares two properties for their
1612 void SemaObjC::DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
1615 bool OverridingProtocolProperty) {
1617 ObjCPropertyAttribute::Kind CAttr = Property->getPropertyAttributes();
1618 ObjCPropertyAttribute::Kind SAttr = SuperProperty->getPropertyAttributes();
1622 // to be overridden by a property with any explicit ownership in the subclass.
1629 Diag(Property->getLocation(), diag::warn_readonly_property)
1630 << Property->getDeclName() << inheritedName;
1633 Diag(Property->getLocation(), diag::warn_property_attribute)
1634 << Property->getDeclName() << "copy" << inheritedName;
1640 bool CStrong = (CAttrRetain != 0);
1641 bool SStrong = (SAttrRetain != 0);
1643 Diag(Property->getLocation(), diag::warn_property_attribute)
1644 << Property->getDeclName() << "retain (or strong)" << inheritedName;
1650 // atomic property is 'readonly'.
1651 checkAtomicPropertyMismatch(SemaRef, SuperProperty, Property, false);
1654 if (Property->getSetterName() != SuperProperty->getSetterName() &&
1655 !(SuperProperty->isReadOnly() &&
1656 isa<ObjCProtocolDecl>(SuperProperty->getDeclContext()))) {
1657 Diag(Property->getLocation(), diag::warn_property_attribute)
1658 << Property->getDeclName() << "setter" << inheritedName;
1659 Diag(SuperProperty->getLocation(), diag::note_property_declare);
1661 if (Property->getGetterName() != SuperProperty->getGetterName()) {
1662 Diag(Property->getLocation(), diag::warn_property_attribute)
1663 << Property->getDeclName() << "getter" << inheritedName;
1664 Diag(SuperProperty->getLocation(), diag::note_property_declare);
1668 Context.getCanonicalType(SuperProperty->getType());
1670 Context.getCanonicalType(Property->getType());
1674 // FIXME. For future support of covariant property types, revisit this.
1675 bool IncompatibleObjC = false;
1680 Diag(Property->getLocation(), diag::warn_property_types_are_incompatible)
1681 << Property->getType() << SuperProperty->getType() << inheritedName;
1682 Diag(SuperProperty->getLocation(), diag::note_property_declare);
1687 bool SemaObjC::DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *property,
1693 QualType GetterType = GetterMethod->getReturnType().getNonReferenceType();
1695 property->getType().getNonReferenceType().getAtomicUnqualifiedType();
1696 bool compat = Context.hasSameType(PropertyRValueType, GetterType);
1701 PropertyRValueType->getAs<ObjCObjectPointerType>()) &&
1702 (getterObjCPtr = GetterType->getAs<ObjCObjectPointerType>()))
1707 << property->getDeclName() << PropertyRValueType
1708 << GetterMethod->getSelector() << GetterType;
1709 Diag(GetterMethod->getLocation(), diag::note_declared_at);
1715 if (lhsType != rhsType && lhsType->isArithmeticType())
1722 << property->getDeclName()
1723 << GetterMethod->getSelector();
1724 Diag(GetterMethod->getLocation(), diag::note_declared_at);
1731 /// CollectImmediateProperties - This routine collects all properties in
1737 bool CollectClassPropsOnly = false,
1738 bool IncludeProtocols = true) {
1740 for (auto *Prop : IDecl->properties()) {
1741 if (CollectClassPropsOnly && !Prop->isClassProperty())
1743 PropMap[std::make_pair(Prop->getIdentifier(), Prop->isClassProperty())] =
1748 for (auto *Ext : IDecl->visible_extensions())
1754 for (auto *PI : IDecl->all_referenced_protocols())
1760 for (auto *Prop : CATDecl->properties()) {
1761 if (CollectClassPropsOnly && !Prop->isClassProperty())
1763 PropMap[std::make_pair(Prop->getIdentifier(), Prop->isClassProperty())] =
1768 for (auto *PI : CATDecl->protocols())
1774 for (auto *Prop : PDecl->properties()) {
1775 if (CollectClassPropsOnly && !Prop->isClassProperty())
1778 SuperPropMap[std::make_pair(Prop->getIdentifier(),
1779 Prop->isClassProperty())];
1780 // Exclude property for protocols which conform to class's super-class,
1781 // as super-class has to implement the property.
1783 PropertyFromSuper->getIdentifier() != Prop->getIdentifier()) {
1785 PropMap[std::make_pair(Prop->getIdentifier(),
1786 Prop->isClassProperty())];
1792 for (auto *PI : PDecl->protocols())
1798 /// CollectSuperClassPropertyImplementations - This routine collects list of
1803 if (ObjCInterfaceDecl *SDecl = CDecl->getSuperClass()) {
1805 SDecl->collectPropertiesToImplement(PropMap);
1806 SDecl = SDecl->getSuperClass();
1811 /// IvarBacksCurrentMethodAccessor - This routine returns 'true' if 'IV' is
1812 /// an ivar synthesized for 'Method' and 'Method' is a property accessor
1814 bool SemaObjC::IvarBacksCurrentMethodAccessor(ObjCInterfaceDecl *IFace,
1817 if (!IV->getSynthesize())
1819 ObjCMethodDecl *IMD = IFace->lookupMethod(Method->getSelector(),
1820 Method->isInstanceMethod());
1821 if (!IMD || !IMD->isPropertyAccessor())
1824 // look up a property declaration whose one of its accessors is implemented
1826 for (const auto *Property : IFace->instance_properties()) {
1827 if ((Property->getGetterName() == IMD->getSelector() ||
1828 Property->getSetterName() == IMD->getSelector()) &&
1829 (Property->getPropertyIvarDecl() == IV))
1832 // Also look up property declaration in class extension whose one of its
1834 for (const auto *Ext : IFace->known_extensions())
1835 for (const auto *Property : Ext->instance_properties())
1836 if ((Property->getGetterName() == IMD->getSelector() ||
1837 Property->getSetterName() == IMD->getSelector()) &&
1838 (Property->getPropertyIvarDecl() == IV))
1843 static bool SuperClassImplementsProperty(ObjCInterfaceDecl *IDecl,
1845 bool SuperClassImplementsGetter = false;
1846 bool SuperClassImplementsSetter = false;
1847 if (Prop->getPropertyAttributes() & ObjCPropertyAttribute::kind_readonly)
1850 while (IDecl->getSuperClass()) {
1851 ObjCInterfaceDecl *SDecl = IDecl->getSuperClass();
1852 if (!SuperClassImplementsGetter && SDecl->getInstanceMethod(Prop->getGetterName()))
1855 if (!SuperClassImplementsSetter && SDecl->getInstanceMethod(Prop->getSetterName()))
1859 IDecl = IDecl->getSuperClass();
1871 IDecl->collectPropertiesToImplement(PropMap);
1879 // Is there a matching property synthesize/dynamic?
1880 if (Prop->isInvalidDecl() ||
1881 Prop->isClassProperty() ||
1882 Prop->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1884 // Property may have been synthesized by user.
1885 if (IMPDecl->FindPropertyImplDecl(
1886 Prop->getIdentifier(), Prop->getQueryKind()))
1888 ObjCMethodDecl *ImpMethod = IMPDecl->getInstanceMethod(Prop->getGetterName());
1889 if (ImpMethod && !ImpMethod->getBody()) {
1890 if (Prop->getPropertyAttributes() & ObjCPropertyAttribute::kind_readonly)
1892 ImpMethod = IMPDecl->getInstanceMethod(Prop->getSetterName());
1893 if (ImpMethod && !ImpMethod->getBody())
1897 IMPDecl->FindPropertyImplIvarDecl(Prop->getIdentifier())) {
1898 Diag(Prop->getLocation(), diag::warn_no_autosynthesis_shared_ivar_property)
1899 << Prop->getIdentifier();
1900 if (PID->getLocation().isValid())
1901 Diag(PID->getLocation(), diag::note_property_synthesize);
1905 SuperPropMap[std::make_pair(Prop->getIdentifier(),
1906 Prop->isClassProperty())];
1908 dyn_cast<ObjCProtocolDecl>(Prop->getDeclContext())) {
1909 // We won't auto-synthesize properties declared in protocols.
1910 // Suppress the warning if class's superclass implements property's
1911 // getter and implements property's setter (if readwrite property).
1912 // Or, if property is going to be implemented in its super class.
1914 Diag(IMPDecl->getLocation(),
1917 Diag(Prop->getLocation(), diag::note_property_declare);
1919 (Twine("@synthesize ") + Prop->getName() + ";\n\n").str();
1925 // If property to be implemented in the super class, ignore.
1927 if ((Prop->getPropertyAttributes() &
1929 (PropInSuperClass->getPropertyAttributes() &
1931 !IMPDecl->getInstanceMethod(Prop->getSetterName()) &&
1932 !IDecl->HasUserDeclaredSetterMethod(Prop)) {
1933 Diag(Prop->getLocation(), diag::warn_no_autosynthesis_property)
1934 << Prop->getIdentifier();
1935 Diag(PropInSuperClass->getLocation(), diag::note_property_declare);
1937 Diag(Prop->getLocation(), diag::warn_autosynthesis_property_in_superclass)
1938 << Prop->getIdentifier();
1939 Diag(PropInSuperClass->getLocation(), diag::note_property_declare);
1940 Diag(IMPDecl->getLocation(), diag::note_while_in_implementation);
1951 /* property = */ Prop->getIdentifier(),
1952 /* ivar = */ Prop->getDefaultSynthIvarName(Context),
1953 Prop->getLocation(), Prop->getQueryKind()));
1954 if (PIDecl && !Prop->isUnavailable()) {
1955 Diag(Prop->getLocation(), diag::warn_missing_explicit_synthesis);
1956 Diag(IMPDecl->getLocation(), diag::note_while_in_implementation);
1969 if (ObjCInterfaceDecl* IDecl = IC->getClassInterface())
1970 if (!IDecl->isObjCRequiresPropertyDefs())
1982 return x->getSelector() == Method &&
1983 x->isClassMethod() == Prop->isClassProperty();
1985 // When reporting on missing property setter/getter implementation in
1991 !PrimaryClass->lookupPropertyAccessor(Method, C,
1992 Prop->isClassProperty()))) {
1995 ? (Prop->isClassProperty()
1998 : (Prop->isClassProperty()
2001 S.Diag(IMPDecl->getLocation(), diag) << Prop->getDeclName() << Method;
2002 S.Diag(Prop->getLocation(), diag::note_property_declare);
2006 if (const ObjCInterfaceDecl *RID = ID->isObjCRequiresPropertyDefs())
2007 S.Diag(RID->getLocation(), diag::note_suppressed_class_declare);
2013 bool SynthesizeProperties) {
2025 // its primary class (and its super classes) if property is
2027 if ((IDecl = C->getClassInterface())) {
2028 IDecl->collectPropertiesToImplement(NoNeedToImplPropMap);
2044 for (auto *PDecl : IDecl->all_referenced_protocols()) {
2045 if (!PDecl->hasAttr<ObjCExplicitProtocolImplAttr>())
2063 for (auto *PropDecl : PDecl->properties()) {
2064 if ((*LazyMap)[std::make_pair(PropDecl->getIdentifier(),
2065 PropDecl->isClassProperty())])
2067 PropMap[std::make_pair(PropDecl->getIdentifier(),
2068 PropDecl->isClassProperty())] = PropDecl;
2077 for (const auto *I : IMPDecl->property_impls())
2078 PropImplMap.insert(I->getPropertyDecl());
2081 // Collect property accessors implemented in current implementation.
2082 for (const auto *I : IMPDecl->methods())
2087 if (C && !C->IsClassExtension())
2088 if ((PrimaryClass = C->getClassInterface()))
2090 if (ObjCImplDecl *IMP = PrimaryClass->getImplementation()) {
2094 for (const auto *I : IMP->methods())
2100 ObjCPropertyDecl *Prop = P->second;
2101 // Is there a matching property synthesize/dynamic?
2102 if (Prop->isInvalidDecl() ||
2103 Prop->getPropertyImplementation() == ObjCPropertyDecl::Optional ||
2105 Prop->getAvailability() == AR_Unavailable)
2109 DiagnoseUnimplementedAccessor(SemaRef, PrimaryClass, Prop->getGetterName(),
2111 if (!Prop->isReadOnly())
2113 Prop->getSetterName(), IMPDecl, CDecl, C,
2120 for (const auto *propertyImpl : impDecl->property_impls()) {
2121 const auto *property = propertyImpl->getPropertyDecl();
2124 if (propertyImpl->getPropertyImplementation() ==
2126 (property->getPropertyAttributes() &
2128 property->getGetterMethodDecl() && property->getSetterMethodDecl()) {
2129 auto *getterImpl = propertyImpl->getGetterMethodDecl();
2130 auto *setterImpl = propertyImpl->getSetterMethodDecl();
2131 if ((!getterImpl || getterImpl->isSynthesizedAccessorStub()) &&
2132 (!setterImpl || setterImpl->isSynthesizedAccessorStub())) {
2133 SourceLocation loc = propertyImpl->getLocation();
2135 loc = impDecl->getBeginLoc();
2138 << setterImpl->getSelector() << property->getDeclName();
2146 // Rules apply in non-GC mode only
2150 for (auto *Prop : IDecl->properties())
2151 PM[std::make_pair(Prop->getIdentifier(), Prop->isClassProperty())] = Prop;
2152 for (const auto *Ext : IDecl->known_extensions())
2153 for (auto *Prop : Ext->properties())
2154 PM[std::make_pair(Prop->getIdentifier(), Prop->isClassProperty())] = Prop;
2158 const ObjCPropertyDecl *Property = I->second;
2162 unsigned Attributes = Property->getPropertyAttributes();
2163 unsigned AttributesAsWritten = Property->getPropertyAttributesAsWritten();
2167 GetterMethod = Property->isClassProperty() ?
2168 IMPDecl->getClassMethod(Property->getGetterName()) :
2169 IMPDecl->getInstanceMethod(Property->getGetterName());
2170 SetterMethod = Property->isClassProperty() ?
2171 IMPDecl->getClassMethod(Property->getSetterName()) :
2172 IMPDecl->getInstanceMethod(Property->getSetterName());
2173 if (GetterMethod && GetterMethod->isSynthesizedAccessorStub())
2175 if (SetterMethod && SetterMethod->isSynthesizedAccessorStub())
2178 Diag(GetterMethod->getLocation(),
2180 << Property->getIdentifier() << 0;
2181 Diag(Property->getLocation(), diag::note_property_declare);
2184 Diag(SetterMethod->getLocation(),
2186 << Property->getIdentifier() << 1;
2187 Diag(Property->getLocation(), diag::note_property_declare);
2191 // We only care about readwrite atomic property.
2195 if (const ObjCPropertyImplDecl *PIDecl = IMPDecl->FindPropertyImplDecl(
2196 Property->getIdentifier(), Property->getQueryKind())) {
2197 if (PIDecl->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic)
2199 GetterMethod = PIDecl->getGetterMethodDecl();
2200 SetterMethod = PIDecl->getSetterMethodDecl();
2201 if (GetterMethod && GetterMethod->isSynthesizedAccessorStub())
2203 if (SetterMethod && SetterMethod->isSynthesizedAccessorStub())
2205 if ((bool)GetterMethod ^ (bool)SetterMethod) {
2207 (GetterMethod ? GetterMethod->getLocation()
2208 : SetterMethod->getLocation());
2210 << Property->getIdentifier() << (GetterMethod != nullptr)
2213 if (Property->getLParenLoc().isValid() &&
2215 // @property () ... case.
2217 SemaRef.getLocForEndOfToken(Property->getLParenLoc());
2220 Diag(Property->getLocation(),
2223 } else if (Property->getLParenLoc().isInvalid()) {
2224 //@property id etc.
2226 Property->getTypeSourceInfo()->getTypeLoc().getBeginLoc();
2227 Diag(Property->getLocation(),
2232 Diag(Property->getLocation(), diag::note_property_declare);
2243 for (const auto *PID : D->property_impls()) {
2244 const ObjCPropertyDecl *PD = PID->getPropertyDecl();
2245 if (PD && !PD->hasAttr<NSReturnsNotRetainedAttr>() &&
2246 !PD->isClassProperty()) {
2247 ObjCMethodDecl *IM = PID->getGetterMethodDecl();
2248 if (IM && !IM->isSynthesizedAccessorStub())
2250 ObjCMethodDecl *method = PD->getGetterMethodDecl();
2253 ObjCMethodFamily family = method->getMethodFamily();
2257 Diag(PD->getLocation(), diag::err_cocoa_naming_owned_rule);
2259 Diag(PD->getLocation(), diag::warn_cocoa_naming_owned_rule);
2261 // Look for a getter explicitly declared alongside the property.
2263 SourceLocation noteLoc = PD->getLocation();
2265 for (auto *getterRedecl : method->redecls()) {
2266 if (getterRedecl->isImplicit())
2268 if (getterRedecl->getDeclContext() != PD->getDeclContext())
2270 noteLoc = getterRedecl->getLocation();
2271 fixItLoc = getterRedecl->getEndLoc();
2287 << method->getDeclName() << spelling;
2300 assert(IFD->hasDesignatedInitializers());
2301 const ObjCInterfaceDecl *SuperD = IFD->getSuperClass();
2306 for (const auto *I : ImplD->instance_methods())
2307 if (I->getMethodFamily() == OMF_init)
2308 InitSelSet.insert(I->getSelector());
2311 SuperD->getDesignatedInitializers(DesignatedInits);
2315 if (!InitSelSet.count(MD->getSelector())) {
2318 bool Ignore = false;
2319 if (auto *IMD = IFD->getInstanceMethod(MD->getSelector())) {
2320 Ignore = IMD->isUnavailable();
2323 for (auto *Ext : IFD->visible_extensions())
2324 if (auto *IMD = Ext->getInstanceMethod(MD->getSelector())) {
2325 Ignore = IMD->isUnavailable();
2330 Diag(ImplD->getLocation(),
2332 << MD->getSelector();
2333 Diag(MD->getLocation(), diag::note_objc_designated_init_marked_here);
2339 /// AddPropertyAttrs - Propagates attributes from a property to the
2340 /// implicitly-declared getter or setter for that property.
2342 ObjCPropertyDecl *Property) {
2344 for (const auto *A : Property->attrs()) {
2348 PropertyMethod->addAttr(A->clone(S.Context));
2352 /// ProcessPropertyDecl - Make sure that any user-defined setter/getter methods
2353 /// have the property type and issue diagnostics if they don't.
2356 void SemaObjC::ProcessPropertyDecl(ObjCPropertyDecl *property) {
2359 ObjCContainerDecl *CD = cast<ObjCContainerDecl>(property->getDeclContext());
2360 if (CD->isInvalidDecl())
2363 bool IsClassProperty = property->isClassProperty();
2365 CD->getClassMethod(property->getGetterName()) :
2366 CD->getInstanceMethod(property->getGetterName());
2372 if (CatDecl->IsClassExtension())
2373 GetterMethod = IsClassProperty ? CatDecl->getClassInterface()->
2374 getClassMethod(property->getGetterName()) :
2375 CatDecl->getClassInterface()->
2376 getInstanceMethod(property->getGetterName());
2379 CD->getClassMethod(property->getSetterName()) :
2380 CD->getInstanceMethod(property->getSetterName());
2383 if (CatDecl->IsClassExtension())
2384 SetterMethod = IsClassProperty ? CatDecl->getClassInterface()->
2385 getClassMethod(property->getSetterName()) :
2386 CatDecl->getClassInterface()->
2387 getInstanceMethod(property->getSetterName());
2388 DiagnosePropertyAccessorMismatch(property, GetterMethod,
2389 property->getLocation());
2395 auto *ExistingGetter = CatDecl->getClassInterface()->lookupMethod(
2396 property->getGetterName(), !IsClassProperty, true, false, CatDecl);
2398 if (ExistingGetter->isDirectMethod() || property->isDirectProperty()) {
2399 Diag(property->getLocation(), diag::err_objc_direct_duplicate_decl)
2400 << property->isDirectProperty() << 1 /* property */
2401 << ExistingGetter->isDirectMethod()
2402 << ExistingGetter->getDeclName();
2403 Diag(ExistingGetter->getLocation(), diag::note_previous_declaration);
2409 if (!property->isReadOnly() && !SetterMethod) {
2411 auto *ExistingSetter = CatDecl->getClassInterface()->lookupMethod(
2412 property->getSetterName(), !IsClassProperty, true, false, CatDecl);
2414 if (ExistingSetter->isDirectMethod() || property->isDirectProperty()) {
2415 Diag(property->getLocation(), diag::err_objc_direct_duplicate_decl)
2416 << property->isDirectProperty() << 1 /* property */
2417 << ExistingSetter->isDirectMethod()
2418 << ExistingSetter->getDeclName();
2419 Diag(ExistingSetter->getLocation(), diag::note_previous_declaration);
2425 if (!property->isReadOnly() && SetterMethod) {
2426 if (Context.getCanonicalType(SetterMethod->getReturnType()) !=
2428 Diag(SetterMethod->getLocation(), diag::err_setter_type_void);
2429 if (SetterMethod->param_size() != 1 ||
2431 (*SetterMethod->param_begin())->getType().getNonReferenceType(),
2432 property->getType().getNonReferenceType())) {
2433 Diag(property->getLocation(),
2435 << property->getDeclName()
2436 << SetterMethod->getSelector();
2437 Diag(SetterMethod->getLocation(), diag::note_declared_at);
2443 // FIXME: The synthesized property we set here is misleading. We almost always
2448 // No instance/class method of same name as property getter name was found.
2451 SourceLocation Loc = property->getLocation();
2453 // The getter returns the declared property type with all qualifiers
2455 QualType resultTy = property->getType().getAtomicUnqualifiedType();
2457 // If the property is null_resettable, the getter returns nonnull.
2458 if (property->getPropertyAttributes() &
2469 Context, Loc, Loc, property->getGetterName(), resultTy, nullptr, CD,
2473 (property->getPropertyImplementation() == ObjCPropertyDecl::Optional)
2476 CD->addDecl(GetterMethod);
2478 AddPropertyAttrs(SemaRef, GetterMethod, property);
2480 if (property->isDirectProperty())
2481 GetterMethod->addAttr(ObjCDirectAttr::CreateImplicit(Context, Loc));
2483 if (property->hasAttr<NSReturnsNotRetainedAttr>())
2484 GetterMethod->addAttr(NSReturnsNotRetainedAttr::CreateImplicit(Context,
2487 if (property->hasAttr<ObjCReturnsInnerPointerAttr>())
2488 GetterMethod->addAttr(
2491 if (const SectionAttr *SA = property->getAttr<SectionAttr>())
2492 GetterMethod->addAttr(SectionAttr::CreateImplicit(
2493 Context, SA->getName(), Loc, SectionAttr::GNU_section));
2501 // the property with the same name is seen in the @implementation
2502 GetterMethod->setPropertyAccessor(true);
2504 GetterMethod->createImplicitParams(Context,
2505 GetterMethod->getClassInterface());
2506 property->setGetterMethodDecl(GetterMethod);
2508 // Skip setter if property is read-only.
2509 if (!property->isReadOnly()) {
2512 // No instance/class method of same name as property setter name was
2516 SourceLocation Loc = property->getLocation();
2519 Context, Loc, Loc, property->getSetterName(), Context.VoidTy, nullptr,
2526 (property->getPropertyImplementation() == ObjCPropertyDecl::Optional)
2532 property->getType().getUnqualifiedType().getAtomicUnqualifiedType();
2534 // If the property is null_resettable, the setter accepts a
2536 if (property->getPropertyAttributes() &
2550 property->getIdentifier(),
2555 SetterMethod->setMethodParams(Context, Argument, std::nullopt);
2557 AddPropertyAttrs(SemaRef, SetterMethod, property);
2559 if (property->isDirectProperty())
2560 SetterMethod->addAttr(ObjCDirectAttr::CreateImplicit(Context, Loc));
2562 CD->addDecl(SetterMethod);
2563 if (const SectionAttr *SA = property->getAttr<SectionAttr>())
2564 SetterMethod->addAttr(SectionAttr::CreateImplicit(
2565 Context, SA->getName(), Loc, SectionAttr::GNU_section));
2575 // the property with the same name is seen in the @implementation
2576 SetterMethod->setPropertyAccessor(true);
2578 SetterMethod->createImplicitParams(Context,
2579 SetterMethod->getClassInterface());
2580 property->setSetterMethodDecl(SetterMethod);
2586 // @property double bar;
2609 CurrentClass = Cat->getClassInterface();
2611 CurrentClass = Impl->getClassInterface();
2621 bool propertyInPrimaryClass) {
2623 if (!PDecl || PDecl->isInvalidDecl())
2632 QualType PropertyTy = PropertyDecl->getType();
2634 // Check for copy or retain on non-object types.
2639 !PropertyTy->isObjCRetainableType() &&
2640 !PropertyDecl->hasAttr<ObjCNSObjectAttr>()) {
2651 PropertyDecl->setInvalidDecl();
2657 PropertyTy->isObjCRetainableType() &&
2658 !PropertyTy->isObjCARCImplicitlyUnretainedType()) {
2685 if (PropertyDecl->hasAttr<IBOutletCollectionAttr>())
2739 if (auto nullability = PropertyTy->getNullability()) {
2753 // Warn if user supplied no assignment attribute, property is
2755 if (!getOwnershipRule(Attributes) && PropertyTy->isObjCRetainableType()) {
2759 // With arc, @property definitions should default to strong when
2761 PropertyDecl->setPropertyAttributes(ObjCPropertyAttribute::kind_strong);
2762 } else if (PropertyTy->isObjCObjectPointerType()) {
2763 bool isAnyClassTy = (PropertyTy->isObjCClassType() ||
2764 PropertyTy->isObjCQualifiedClassType());
2765 // In non-gc, non-arc mode, 'Class' is treated as a 'void *' no need to
2770 // Don't issue warning on property with no life time in class
2771 // extension as it is inherited from property in primary class.
2772 // Skip this warning in gc-only mode.
2776 // If non-gc code warn that this is likely inappropriate.
2789 PropertyTy->isBlockPointerType())
2794 PropertyTy->isBlockPointerType())