clang 8.0.0

SemaObjCProperty.cpp
Go to the documentation of this file.
1 //===--- SemaObjCProperty.cpp - Semantic Analysis for ObjC @property ------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements semantic analysis for Objective C @property and
11 // @synthesize declarations.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "clang/Sema/SemaInternal.h"
16 #include "clang/AST/ASTMutationListener.h"
17 #include "clang/AST/DeclObjC.h"
18 #include "clang/AST/ExprCXX.h"
19 #include "clang/AST/ExprObjC.h"
20 #include "clang/Basic/SourceManager.h"
21 #include "clang/Lex/Lexer.h"
22 #include "clang/Lex/Preprocessor.h"
23 #include "clang/Sema/Initialization.h"
24 #include "llvm/ADT/DenseSet.h"
25 #include "llvm/ADT/SmallString.h"
26
27 using namespace clang;
28
29 //===----------------------------------------------------------------------===//
30 // Grammar actions.
31 //===----------------------------------------------------------------------===//
32
33 /// getImpliedARCOwnership - Given a set of property attributes and a
34 /// type, infer an expected lifetime. The type's ownership qualification
35 /// is not considered.
36 ///
37 /// Returns OCL_None if the attributes as stated do not imply an ownership.
38 /// Never returns OCL_Autoreleasing.
39 static Qualifiers::ObjCLifetime getImpliedARCOwnership(
40 ObjCPropertyDecl::PropertyAttributeKind attrs,
41 QualType type) {
42 // retain, strong, copy, weak, and unsafe_unretained are only legal
43 // on properties of retainable pointer type.
44 if (attrs & (ObjCPropertyDecl::OBJC_PR_retain |
45 ObjCPropertyDecl::OBJC_PR_strong |
46 ObjCPropertyDecl::OBJC_PR_copy)) {
47 return Qualifiers::OCL_Strong;
48 } else if (attrs & ObjCPropertyDecl::OBJC_PR_weak) {
49 return Qualifiers::OCL_Weak;
50 } else if (attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained) {
51 return Qualifiers::OCL_ExplicitNone;
52 }
53
54 // assign can appear on other types, so we have to check the
55 // property type.
56 if (attrs & ObjCPropertyDecl::OBJC_PR_assign &&
57 type->isObjCRetainableType()) {
58 return Qualifiers::OCL_ExplicitNone;
59 }
60
61 return Qualifiers::OCL_None;
62 }
63
64 /// Check the internal consistency of a property declaration with
65 /// an explicit ownership qualifier.
66 static void checkPropertyDeclWithOwnership(Sema &S,
67 ObjCPropertyDecl *property) {
68 if (property->isInvalidDecl()) return;
69
70 ObjCPropertyDecl::PropertyAttributeKind propertyKind
71 = property->getPropertyAttributes();
72 Qualifiers::ObjCLifetime propertyLifetime
73 = property->getType().getObjCLifetime();
74
75 assert(propertyLifetime != Qualifiers::OCL_None);
76
77 Qualifiers::ObjCLifetime expectedLifetime
78 = getImpliedARCOwnership(propertyKind, property->getType());
79 if (!expectedLifetime) {
80 // We have a lifetime qualifier but no dominating property
81 // attribute. That's okay, but restore reasonable invariants by
82 // setting the property attribute according to the lifetime
83 // qualifier.
84 ObjCPropertyDecl::PropertyAttributeKind attr;
85 if (propertyLifetime == Qualifiers::OCL_Strong) {
86 attr = ObjCPropertyDecl::OBJC_PR_strong;
87 } else if (propertyLifetime == Qualifiers::OCL_Weak) {
88 attr = ObjCPropertyDecl::OBJC_PR_weak;
89 } else {
90 assert(propertyLifetime == Qualifiers::OCL_ExplicitNone);
91 attr = ObjCPropertyDecl::OBJC_PR_unsafe_unretained;
92 }
93 property->setPropertyAttributes(attr);
94 return;
95 }
96
97 if (propertyLifetime == expectedLifetime) return;
98
99 property->setInvalidDecl();
100 S.Diag(property->getLocation(),
101 diag::err_arc_inconsistent_property_ownership)
102 << property->getDeclName()
103 << expectedLifetime
104 << propertyLifetime;
105 }
106
107 /// Check this Objective-C property against a property declared in the
108 /// given protocol.
109 static void
110 CheckPropertyAgainstProtocol(Sema &S, ObjCPropertyDecl *Prop,
111 ObjCProtocolDecl *Proto,
112 llvm::SmallPtrSetImpl<ObjCProtocolDecl *> &Known) {
113 // Have we seen this protocol before?
114 if (!Known.insert(Proto).second)
115 return;
116
117 // Look for a property with the same name.
118 DeclContext::lookup_result R = Proto->lookup(Prop->getDeclName());
119 for (unsigned I = 0, N = R.size(); I != N; ++I) {
120 if (ObjCPropertyDecl *ProtoProp = dyn_cast<ObjCPropertyDecl>(R[I])) {
121 S.DiagnosePropertyMismatch(Prop, ProtoProp, Proto->getIdentifier(), true);
122 return;
123 }
124 }
125
126 // Check this property against any protocols we inherit.
127 for (auto *P : Proto->protocols())
128 CheckPropertyAgainstProtocol(S, Prop, P, Known);
129 }
130
131 static unsigned deducePropertyOwnershipFromType(Sema &S, QualType T) {
132 // In GC mode, just look for the __weak qualifier.
133 if (S.getLangOpts().getGC() != LangOptions::NonGC) {
134 if (T.isObjCGCWeak()) return ObjCDeclSpec::DQ_PR_weak;
135
136 // In ARC/MRC, look for an explicit ownership qualifier.
137 // For some reason, this only applies to __weak.
138 } else if (auto ownership = T.getObjCLifetime()) {
139 switch (ownership) {
140 case Qualifiers::OCL_Weak:
141 return ObjCDeclSpec::DQ_PR_weak;
142 case Qualifiers::OCL_Strong:
143 return ObjCDeclSpec::DQ_PR_strong;
144 case Qualifiers::OCL_ExplicitNone:
145 return ObjCDeclSpec::DQ_PR_unsafe_unretained;
146 case Qualifiers::OCL_Autoreleasing:
147 case Qualifiers::OCL_None:
148 return 0;
149 }
150 llvm_unreachable("bad qualifier");
151 }
152
153 return 0;
154 }
155
156 static const unsigned OwnershipMask =
157 (ObjCPropertyDecl::OBJC_PR_assign |
158 ObjCPropertyDecl::OBJC_PR_retain |
159 ObjCPropertyDecl::OBJC_PR_copy |
160 ObjCPropertyDecl::OBJC_PR_weak |
161 ObjCPropertyDecl::OBJC_PR_strong |
162 ObjCPropertyDecl::OBJC_PR_unsafe_unretained);
163
164 static unsigned getOwnershipRule(unsigned attr) {
165 unsigned result = attr & OwnershipMask;
166
167 // From an ownership perspective, assign and unsafe_unretained are
168 // identical; make sure one also implies the other.
169 if (result & (ObjCPropertyDecl::OBJC_PR_assign |
170 ObjCPropertyDecl::OBJC_PR_unsafe_unretained)) {
171 result |= ObjCPropertyDecl::OBJC_PR_assign |
172 ObjCPropertyDecl::OBJC_PR_unsafe_unretained;
173 }
174
175 return result;
176 }
177
178 Decl *Sema::ActOnProperty(Scope *S, SourceLocation AtLoc,
179 SourceLocation LParenLoc,
180 FieldDeclarator &FD,
181 ObjCDeclSpec &ODS,
182 Selector GetterSel,
183 Selector SetterSel,
184 tok::ObjCKeywordKind MethodImplKind,
185 DeclContext *lexicalDC) {
186 unsigned Attributes = ODS.getPropertyAttributes();
187 FD.D.setObjCWeakProperty((Attributes & ObjCDeclSpec::DQ_PR_weak) != 0);
188 TypeSourceInfo *TSI = GetTypeForDeclarator(FD.D, S);
189 QualType T = TSI->getType();
190 if (!getOwnershipRule(Attributes)) {
191 Attributes |= deducePropertyOwnershipFromType(*this, T);
192 }
193 bool isReadWrite = ((Attributes & ObjCDeclSpec::DQ_PR_readwrite) ||
194 // default is readwrite!
195 !(Attributes & ObjCDeclSpec::DQ_PR_readonly));
196
197 // Proceed with constructing the ObjCPropertyDecls.
198 ObjCContainerDecl *ClassDecl = cast<ObjCContainerDecl>(CurContext);
199 ObjCPropertyDecl *Res = nullptr;
200 if (ObjCCategoryDecl *CDecl = dyn_cast<ObjCCategoryDecl>(ClassDecl)) {
201 if (CDecl->IsClassExtension()) {
202 Res = HandlePropertyInClassExtension(S, AtLoc, LParenLoc,
203 FD,
204 GetterSel, ODS.getGetterNameLoc(),
205 SetterSel, ODS.getSetterNameLoc(),
206 isReadWrite, Attributes,
207 ODS.getPropertyAttributes(),
208 T, TSI, MethodImplKind);
209 if (!Res)
210 return nullptr;
211 }
212 }
213
214 if (!Res) {
215 Res = CreatePropertyDecl(S, ClassDecl, AtLoc, LParenLoc, FD,
216 GetterSel, ODS.getGetterNameLoc(), SetterSel,
217 ODS.getSetterNameLoc(), isReadWrite, Attributes,
218 ODS.getPropertyAttributes(), T, TSI,
219 MethodImplKind);
220 if (lexicalDC)
221 Res->setLexicalDeclContext(lexicalDC);
222 }
223
224 // Validate the attributes on the @property.
225 CheckObjCPropertyAttributes(Res, AtLoc, Attributes,
226 (isa<ObjCInterfaceDecl>(ClassDecl) ||
227 isa<ObjCProtocolDecl>(ClassDecl)));
228
229 // Check consistency if the type has explicit ownership qualification.
230 if (Res->getType().getObjCLifetime())
231 checkPropertyDeclWithOwnership(*this, Res);
232
233 llvm::SmallPtrSet<ObjCProtocolDecl *, 16> KnownProtos;
234 if (ObjCInterfaceDecl *IFace = dyn_cast<ObjCInterfaceDecl>(ClassDecl)) {
235 // For a class, compare the property against a property in our superclass.
236 bool FoundInSuper = false;
237 ObjCInterfaceDecl *CurrentInterfaceDecl = IFace;
238 while (ObjCInterfaceDecl *Super = CurrentInterfaceDecl->getSuperClass()) {
239 DeclContext::lookup_result R = Super->lookup(Res->getDeclName());
240 for (unsigned I = 0, N = R.size(); I != N; ++I) {
241 if (ObjCPropertyDecl *SuperProp = dyn_cast<ObjCPropertyDecl>(R[I])) {
242 DiagnosePropertyMismatch(Res, SuperProp, Super->getIdentifier(), false);
243 FoundInSuper = true;
244 break;
245 }
246 }
247 if (FoundInSuper)
248 break;
249 else
250 CurrentInterfaceDecl = Super;
251 }
252
253 if (FoundInSuper) {
254 // Also compare the property against a property in our protocols.
255 for (auto *P : CurrentInterfaceDecl->protocols()) {
256 CheckPropertyAgainstProtocol(*this, Res, P, KnownProtos);
257 }
258 } else {
259 // Slower path: look in all protocols we referenced.
260 for (auto *P : IFace->all_referenced_protocols()) {
261 CheckPropertyAgainstProtocol(*this, Res, P, KnownProtos);
262 }
263 }
264 } else if (ObjCCategoryDecl *Cat = dyn_cast<ObjCCategoryDecl>(ClassDecl)) {
265 // We don't check if class extension. Because properties in class extension
266 // are meant to override some of the attributes and checking has already done
267 // when property in class extension is constructed.
268 if (!Cat->IsClassExtension())
269 for (auto *P : Cat->protocols())
270 CheckPropertyAgainstProtocol(*this, Res, P, KnownProtos);
271 } else {
272 ObjCProtocolDecl *Proto = cast<ObjCProtocolDecl>(ClassDecl);
273 for (auto *P : Proto->protocols())
274 CheckPropertyAgainstProtocol(*this, Res, P, KnownProtos);
275 }
276
277 ActOnDocumentableDecl(Res);
278 return Res;
279 }
280
281 static ObjCPropertyDecl::PropertyAttributeKind
282 makePropertyAttributesAsWritten(unsigned Attributes) {
283 unsigned attributesAsWritten = 0;
284 if (Attributes & ObjCDeclSpec::DQ_PR_readonly)
285 attributesAsWritten |= ObjCPropertyDecl::OBJC_PR_readonly;
286 if (Attributes & ObjCDeclSpec::DQ_PR_readwrite)
287 attributesAsWritten |= ObjCPropertyDecl::OBJC_PR_readwrite;
288 if (Attributes & ObjCDeclSpec::DQ_PR_getter)
289 attributesAsWritten |= ObjCPropertyDecl::OBJC_PR_getter;
290 if (Attributes & ObjCDeclSpec::DQ_PR_setter)
291 attributesAsWritten |= ObjCPropertyDecl::OBJC_PR_setter;
292 if (Attributes & ObjCDeclSpec::DQ_PR_assign)
293 attributesAsWritten |= ObjCPropertyDecl::OBJC_PR_assign;
294 if (Attributes & ObjCDeclSpec::DQ_PR_retain)
295 attributesAsWritten |= ObjCPropertyDecl::OBJC_PR_retain;
296 if (Attributes & ObjCDeclSpec::DQ_PR_strong)
297 attributesAsWritten |= ObjCPropertyDecl::OBJC_PR_strong;
298 if (Attributes & ObjCDeclSpec::DQ_PR_weak)
299 attributesAsWritten |= ObjCPropertyDecl::OBJC_PR_weak;
300 if (Attributes & ObjCDeclSpec::DQ_PR_copy)
301 attributesAsWritten |= ObjCPropertyDecl::OBJC_PR_copy;
302 if (Attributes & ObjCDeclSpec::DQ_PR_unsafe_unretained)
303 attributesAsWritten |= ObjCPropertyDecl::OBJC_PR_unsafe_unretained;
304 if (Attributes & ObjCDeclSpec::DQ_PR_nonatomic)
305 attributesAsWritten |= ObjCPropertyDecl::OBJC_PR_nonatomic;
306 if (Attributes & ObjCDeclSpec::DQ_PR_atomic)
307 attributesAsWritten |= ObjCPropertyDecl::OBJC_PR_atomic;
308 if (Attributes & ObjCDeclSpec::DQ_PR_class)
309 attributesAsWritten |= ObjCPropertyDecl::OBJC_PR_class;
310
311 return (ObjCPropertyDecl::PropertyAttributeKind)attributesAsWritten;
312 }
313
314 static bool LocPropertyAttribute( ASTContext &Context, const char *attrName,
315 SourceLocation LParenLoc, SourceLocation &Loc) {
316 if (LParenLoc.isMacroID())
317 return false;
318
319 SourceManager &SM = Context.getSourceManager();
320 std::pair<FileID, unsigned> locInfo = SM.getDecomposedLoc(LParenLoc);
321 // Try to load the file buffer.
322 bool invalidTemp = false;
323 StringRef file = SM.getBufferData(locInfo.first, &invalidTemp);
324 if (invalidTemp)
325 return false;
326 const char *tokenBegin = file.data() + locInfo.second;
327
328 // Lex from the start of the given location.
329 Lexer lexer(SM.getLocForStartOfFile(locInfo.first),
330 Context.getLangOpts(),
331 file.begin(), tokenBegin, file.end());
332 Token Tok;
333 do {
334 lexer.LexFromRawLexer(Tok);
335 if (Tok.is(tok::raw_identifier) && Tok.getRawIdentifier() == attrName) {
336 Loc = Tok.getLocation();
337 return true;
338 }
339 } while (Tok.isNot(tok::r_paren));
340 return false;
341 }
342
343 /// Check for a mismatch in the atomicity of the given properties.
344 static void checkAtomicPropertyMismatch(Sema &S,
345 ObjCPropertyDecl *OldProperty,
346 ObjCPropertyDecl *NewProperty,
347 bool PropagateAtomicity) {
348 // If the atomicity of both matches, we're done.
349 bool OldIsAtomic =
350 (OldProperty->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_nonatomic)
351 == 0;
352 bool NewIsAtomic =
353 (NewProperty->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_nonatomic)
354 == 0;
355 if (OldIsAtomic == NewIsAtomic) return;
356
357 // Determine whether the given property is readonly and implicitly
358 // atomic.
359 auto isImplicitlyReadonlyAtomic = [](ObjCPropertyDecl *Property) -> bool {
360 // Is it readonly?
361 auto Attrs = Property->getPropertyAttributes();
362 if ((Attrs & ObjCPropertyDecl::OBJC_PR_readonly) == 0) return false;
363
364 // Is it nonatomic?
365 if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic) return false;
366
367 // Was 'atomic' specified directly?
368 if (Property->getPropertyAttributesAsWritten() &
369 ObjCPropertyDecl::OBJC_PR_atomic)
370 return false;
371
372 return true;
373 };
374
375 // If we're allowed to propagate atomicity, and the new property did
376 // not specify atomicity at all, propagate.
377 const unsigned AtomicityMask =
378 (ObjCPropertyDecl::OBJC_PR_atomic | ObjCPropertyDecl::OBJC_PR_nonatomic);
379 if (PropagateAtomicity &&
380 ((NewProperty->getPropertyAttributesAsWritten() & AtomicityMask) == 0)) {
381 unsigned Attrs = NewProperty->getPropertyAttributes();
382 Attrs = Attrs & ~AtomicityMask;
383 if (OldIsAtomic)
384 Attrs |= ObjCPropertyDecl::OBJC_PR_atomic;
385 else
386 Attrs |= ObjCPropertyDecl::OBJC_PR_nonatomic;
387
388 NewProperty->overwritePropertyAttributes(Attrs);
389 return;
390 }
391
392 // One of the properties is atomic; if it's a readonly property, and
393 // 'atomic' wasn't explicitly specified, we're okay.
394 if ((OldIsAtomic && isImplicitlyReadonlyAtomic(OldProperty)) ||
395 (NewIsAtomic && isImplicitlyReadonlyAtomic(NewProperty)))
396 return;
397
398 // Diagnose the conflict.
399 const IdentifierInfo *OldContextName;
400 auto *OldDC = OldProperty->getDeclContext();
401 if (auto Category = dyn_cast<ObjCCategoryDecl>(OldDC))
402 OldContextName = Category->getClassInterface()->getIdentifier();
403 else
404 OldContextName = cast<ObjCContainerDecl>(OldDC)->getIdentifier();
405
406 S.Diag(NewProperty->getLocation(), diag::warn_property_attribute)
407 << NewProperty->getDeclName() << "atomic"
408 << OldContextName;
409 S.Diag(OldProperty->getLocation(), diag::note_property_declare);
410 }
411
412 ObjCPropertyDecl *
413 Sema::HandlePropertyInClassExtension(Scope *S,
414 SourceLocation AtLoc,
415 SourceLocation LParenLoc,
416 FieldDeclarator &FD,
417 Selector GetterSel,
418 SourceLocation GetterNameLoc,
419 Selector SetterSel,
420 SourceLocation SetterNameLoc,
421 const bool isReadWrite,
422 unsigned &Attributes,
423 const unsigned AttributesAsWritten,
424 QualType T,
425 TypeSourceInfo *TSI,
426 tok::ObjCKeywordKind MethodImplKind) {
427 ObjCCategoryDecl *CDecl = cast<ObjCCategoryDecl>(CurContext);
428 // Diagnose if this property is already in continuation class.
429 DeclContext *DC = CurContext;
430 IdentifierInfo *PropertyId = FD.D.getIdentifier();
431 ObjCInterfaceDecl *CCPrimary = CDecl->getClassInterface();
432
433 // We need to look in the @interface to see if the @property was
434 // already declared.
435 if (!CCPrimary) {
436 Diag(CDecl->getLocation(), diag::err_continuation_class);
437 return nullptr;
438 }
439
440 bool isClassProperty = (AttributesAsWritten & ObjCDeclSpec::DQ_PR_class) ||
441 (Attributes & ObjCDeclSpec::DQ_PR_class);
442
443 // Find the property in the extended class's primary class or
444 // extensions.
445 ObjCPropertyDecl *PIDecl = CCPrimary->FindPropertyVisibleInPrimaryClass(
446 PropertyId, ObjCPropertyDecl::getQueryKind(isClassProperty));
447
448 // If we found a property in an extension, complain.
449 if (PIDecl && isa<ObjCCategoryDecl>(PIDecl->getDeclContext())) {
450 Diag(AtLoc, diag::err_duplicate_property);
451 Diag(PIDecl->getLocation(), diag::note_property_declare);
452 return nullptr;
453 }
454
455 // Check for consistency with the previous declaration, if there is one.
456 if (PIDecl) {
457 // A readonly property declared in the primary class can be refined
458 // by adding a readwrite property within an extension.
459 // Anything else is an error.
460 if (!(PIDecl->isReadOnly() && isReadWrite)) {
461 // Tailor the diagnostics for the common case where a readwrite
462 // property is declared both in the @interface and the continuation.
463 // This is a common error where the user often intended the original
464 // declaration to be readonly.
465 unsigned diag =
466 (Attributes & ObjCDeclSpec::DQ_PR_readwrite) &&
467 (PIDecl->getPropertyAttributesAsWritten() &
468 ObjCPropertyDecl::OBJC_PR_readwrite)
469 ? diag::err_use_continuation_class_redeclaration_readwrite
470 : diag::err_use_continuation_class;
471 Diag(AtLoc, diag)
472 << CCPrimary->getDeclName();
473 Diag(PIDecl->getLocation(), diag::note_property_declare);
474 return nullptr;
475 }
476
477 // Check for consistency of getters.
478 if (PIDecl->getGetterName() != GetterSel) {
479 // If the getter was written explicitly, complain.
480 if (AttributesAsWritten & ObjCDeclSpec::DQ_PR_getter) {
481 Diag(AtLoc, diag::warn_property_redecl_getter_mismatch)
482 << PIDecl->getGetterName() << GetterSel;
483 Diag(PIDecl->getLocation(), diag::note_property_declare);
484 }
485
486 // Always adopt the getter from the original declaration.
487 GetterSel = PIDecl->getGetterName();
488 Attributes |= ObjCDeclSpec::DQ_PR_getter;
489 }
490
491 // Check consistency of ownership.
492 unsigned ExistingOwnership
493 = getOwnershipRule(PIDecl->getPropertyAttributes());
494 unsigned NewOwnership = getOwnershipRule(Attributes);
495 if (ExistingOwnership && NewOwnership != ExistingOwnership) {
496 // If the ownership was written explicitly, complain.
497 if (getOwnershipRule(AttributesAsWritten)) {
498 Diag(AtLoc, diag::warn_property_attr_mismatch);
499 Diag(PIDecl->getLocation(), diag::note_property_declare);
500 }
501
502 // Take the ownership from the original property.
503 Attributes = (Attributes & ~OwnershipMask) | ExistingOwnership;
504 }
505
506 // If the redeclaration is 'weak' but the original property is not,
507 if ((Attributes & ObjCPropertyDecl::OBJC_PR_weak) &&
508 !(PIDecl->getPropertyAttributesAsWritten()
509 & ObjCPropertyDecl::OBJC_PR_weak) &&
510 PIDecl->getType()->getAs<ObjCObjectPointerType>() &&
511 PIDecl->getType().getObjCLifetime() == Qualifiers::OCL_None) {
512 Diag(AtLoc, diag::warn_property_implicitly_mismatched);
513 Diag(PIDecl->getLocation(), diag::note_property_declare);
514 }
515 }
516
517 // Create a new ObjCPropertyDecl with the DeclContext being
518 // the class extension.
519 ObjCPropertyDecl *PDecl = CreatePropertyDecl(S, CDecl, AtLoc, LParenLoc,
520 FD, GetterSel, GetterNameLoc,
521 SetterSel, SetterNameLoc,
522 isReadWrite,
523 Attributes, AttributesAsWritten,
524 T, TSI, MethodImplKind, DC);
525
526 // If there was no declaration of a property with the same name in
527 // the primary class, we're done.
528 if (!PIDecl) {
529 ProcessPropertyDecl(PDecl);
530 return PDecl;
531 }
532
533 if (!Context.hasSameType(PIDecl->getType(), PDecl->getType())) {
534 bool IncompatibleObjC = false;
535 QualType ConvertedType;
536 // Relax the strict type matching for property type in continuation class.
537 // Allow property object type of continuation class to be different as long
538 // as it narrows the object type in its primary class property. Note that
539 // this conversion is safe only because the wider type is for a 'readonly'
540 // property in primary class and 'narrowed' type for a 'readwrite' property
541 // in continuation class.
542 QualType PrimaryClassPropertyT = Context.getCanonicalType(PIDecl->getType());
543 QualType ClassExtPropertyT = Context.getCanonicalType(PDecl->getType());
544 if (!isa<ObjCObjectPointerType>(PrimaryClassPropertyT) ||
545 !isa<ObjCObjectPointerType>(ClassExtPropertyT) ||
546 (!isObjCPointerConversion(ClassExtPropertyT, PrimaryClassPropertyT,
547 ConvertedType, IncompatibleObjC))
548 || IncompatibleObjC) {
549 Diag(AtLoc,
550 diag::err_type_mismatch_continuation_class) << PDecl->getType();
551 Diag(PIDecl->getLocation(), diag::note_property_declare);
552 return nullptr;
553 }
554 }
555
556 // Check that atomicity of property in class extension matches the previous
557 // declaration.
558 checkAtomicPropertyMismatch(*this, PIDecl, PDecl, true);
559
560 // Make sure getter/setter are appropriately synthesized.
561 ProcessPropertyDecl(PDecl);
562 return PDecl;
563 }
564
565 ObjCPropertyDecl *Sema::CreatePropertyDecl(Scope *S,
566 ObjCContainerDecl *CDecl,
567 SourceLocation AtLoc,
568 SourceLocation LParenLoc,
569 FieldDeclarator &FD,
570 Selector GetterSel,
571 SourceLocation GetterNameLoc,
572 Selector SetterSel,
573 SourceLocation SetterNameLoc,
574 const bool isReadWrite,
575 const unsigned Attributes,
576 const unsigned AttributesAsWritten,
577 QualType T,
578 TypeSourceInfo *TInfo,
579 tok::ObjCKeywordKind MethodImplKind,
580 DeclContext *lexicalDC){
581 IdentifierInfo *PropertyId = FD.D.getIdentifier();
582
583 // Property defaults to 'assign' if it is readwrite, unless this is ARC
584 // and the type is retainable.
585 bool isAssign;
586 if (Attributes & (ObjCDeclSpec::DQ_PR_assign |
587 ObjCDeclSpec::DQ_PR_unsafe_unretained)) {
588 isAssign = true;
589 } else if (getOwnershipRule(Attributes) || !isReadWrite) {
590 isAssign = false;
591 } else {
592 isAssign = (!getLangOpts().ObjCAutoRefCount ||
593 !T->isObjCRetainableType());
594 }
595
596 // Issue a warning if property is 'assign' as default and its
597 // object, which is gc'able conforms to NSCopying protocol
598 if (getLangOpts().getGC() != LangOptions::NonGC &&
599 isAssign && !(Attributes & ObjCDeclSpec::DQ_PR_assign)) {
600 if (const ObjCObjectPointerType *ObjPtrTy =
601 T->getAs<ObjCObjectPointerType>()) {
602 ObjCInterfaceDecl *IDecl = ObjPtrTy->getObjectType()->getInterface();
603 if (IDecl)
604 if (ObjCProtocolDecl* PNSCopying =
605 LookupProtocol(&Context.Idents.get("NSCopying"), AtLoc))
606 if (IDecl->ClassImplementsProtocol(PNSCopying, true))
607 Diag(AtLoc, diag::warn_implements_nscopying) << PropertyId;
608 }
609 }
610
611 if (T->isObjCObjectType()) {
612 SourceLocation StarLoc = TInfo->getTypeLoc().getEndLoc();
613 StarLoc = getLocForEndOfToken(StarLoc);
614 Diag(FD.D.getIdentifierLoc(), diag::err_statically_allocated_object)
615 << FixItHint::CreateInsertion(StarLoc, "*");
616 T = Context.getObjCObjectPointerType(T);
617 SourceLocation TLoc = TInfo->getTypeLoc().getBeginLoc();
618 TInfo = Context.getTrivialTypeSourceInfo(T, TLoc);
619 }
620
621 DeclContext *DC = CDecl;
622 ObjCPropertyDecl *PDecl = ObjCPropertyDecl::Create(Context, DC,
623 FD.D.getIdentifierLoc(),
624 PropertyId, AtLoc,
625 LParenLoc, T, TInfo);
626
627 bool isClassProperty = (AttributesAsWritten & ObjCDeclSpec::DQ_PR_class) ||
628 (Attributes & ObjCDeclSpec::DQ_PR_class);
629 // Class property and instance property can have the same name.
630 if (ObjCPropertyDecl *prevDecl = ObjCPropertyDecl::findPropertyDecl(
631 DC, PropertyId, ObjCPropertyDecl::getQueryKind(isClassProperty))) {
632 Diag(PDecl->getLocation(), diag::err_duplicate_property);
633 Diag(prevDecl->getLocation(), diag::note_property_declare);
634 PDecl->setInvalidDecl();
635 }
636 else {
637 DC->addDecl(PDecl);
638 if (lexicalDC)
639 PDecl->setLexicalDeclContext(lexicalDC);
640 }
641
642 if (T->isArrayType() || T->isFunctionType()) {
643 Diag(AtLoc, diag::err_property_type) << T;
644 PDecl->setInvalidDecl();
645 }
646
647 ProcessDeclAttributes(S, PDecl, FD.D);
648
649 // Regardless of setter/getter attribute, we save the default getter/setter
650 // selector names in anticipation of declaration of setter/getter methods.
651 PDecl->setGetterName(GetterSel, GetterNameLoc);
652 PDecl->setSetterName(SetterSel, SetterNameLoc);
653 PDecl->setPropertyAttributesAsWritten(
654 makePropertyAttributesAsWritten(AttributesAsWritten));
655
656 if (Attributes & ObjCDeclSpec::DQ_PR_readonly)
657 PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_readonly);
658
659 if (Attributes & ObjCDeclSpec::DQ_PR_getter)
660 PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_getter);
661
662 if (Attributes & ObjCDeclSpec::DQ_PR_setter)
663 PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_setter);
664
665 if (isReadWrite)
666 PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_readwrite);
667
668 if (Attributes & ObjCDeclSpec::DQ_PR_retain)
669 PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_retain);
670
671 if (Attributes & ObjCDeclSpec::DQ_PR_strong)
672 PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_strong);
673
674 if (Attributes & ObjCDeclSpec::DQ_PR_weak)
675 PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_weak);
676
677 if (Attributes & ObjCDeclSpec::DQ_PR_copy)
678 PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_copy);
679
680 if (Attributes & ObjCDeclSpec::DQ_PR_unsafe_unretained)
681 PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_unsafe_unretained);
682
683 if (isAssign)
684 PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_assign);
685
686 // In the semantic attributes, one of nonatomic or atomic is always set.
687 if (Attributes & ObjCDeclSpec::DQ_PR_nonatomic)
688 PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_nonatomic);
689 else
690 PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_atomic);
691
692 // 'unsafe_unretained' is alias for 'assign'.
693 if (Attributes & ObjCDeclSpec::DQ_PR_unsafe_unretained)
694 PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_assign);
695 if (isAssign)
696 PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_unsafe_unretained);
697
698 if (MethodImplKind == tok::objc_required)
699 PDecl->setPropertyImplementation(ObjCPropertyDecl::Required);
700 else if (MethodImplKind == tok::objc_optional)
701 PDecl->setPropertyImplementation(ObjCPropertyDecl::Optional);
702
703 if (Attributes & ObjCDeclSpec::DQ_PR_nullability)
704 PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_nullability);
705
706 if (Attributes & ObjCDeclSpec::DQ_PR_null_resettable)
707 PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_null_resettable);
708
709 if (Attributes & ObjCDeclSpec::DQ_PR_class)
710 PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_class);
711
712 return PDecl;
713 }
714
715 static void checkARCPropertyImpl(Sema &S, SourceLocation propertyImplLoc,
716 ObjCPropertyDecl *property,
717 ObjCIvarDecl *ivar) {
718 if (property->isInvalidDecl() || ivar->isInvalidDecl()) return;
719
720 QualType ivarType = ivar->getType();
721 Qualifiers::ObjCLifetime ivarLifetime = ivarType.getObjCLifetime();
722
723 // The lifetime implied by the property's attributes.
724 Qualifiers::ObjCLifetime propertyLifetime =
725 getImpliedARCOwnership(property->getPropertyAttributes(),
726 property->getType());
727
728 // We're fine if they match.
729 if (propertyLifetime == ivarLifetime) return;
730
731 // None isn't a valid lifetime for an object ivar in ARC, and
732 // __autoreleasing is never valid; don't diagnose twice.
733 if ((ivarLifetime == Qualifiers::OCL_None &&
734 S.getLangOpts().ObjCAutoRefCount) ||
735 ivarLifetime == Qualifiers::OCL_Autoreleasing)
736 return;
737
738 // If the ivar is private, and it's implicitly __unsafe_unretained
739 // becaues of its type, then pretend it was actually implicitly
740 // __strong. This is only sound because we're processing the
741 // property implementation before parsing any method bodies.
742 if (ivarLifetime == Qualifiers::OCL_ExplicitNone &&
743 propertyLifetime == Qualifiers::OCL_Strong &&
744 ivar->getAccessControl() == ObjCIvarDecl::Private) {
745 SplitQualType split = ivarType.split();
746 if (split.Quals.hasObjCLifetime()) {
747 assert(ivarType->isObjCARCImplicitlyUnretainedType());
748 split.Quals.setObjCLifetime(Qualifiers::OCL_Strong);
749 ivarType = S.Context.getQualifiedType(split);
750 ivar->setType(ivarType);
751 return;
752 }
753 }
754
755 switch (propertyLifetime) {
756 case Qualifiers::OCL_Strong:
757 S.Diag(ivar->getLocation(), diag::err_arc_strong_property_ownership)
758 << property->getDeclName()
759 << ivar->getDeclName()
760 << ivarLifetime;
761 break;
762
763 case Qualifiers::OCL_Weak:
764 S.Diag(ivar->getLocation(), diag::err_weak_property)
765 << property->getDeclName()
766 << ivar->getDeclName();
767 break;
768
769 case Qualifiers::OCL_ExplicitNone:
770 S.Diag(ivar->getLocation(), diag::err_arc_assign_property_ownership)
771 << property->getDeclName()
772 << ivar->getDeclName()
773 << ((property->getPropertyAttributesAsWritten()
774 & ObjCPropertyDecl::OBJC_PR_assign) != 0);
775 break;
776
777 case Qualifiers::OCL_Autoreleasing:
778 llvm_unreachable("properties cannot be autoreleasing");
779
780 case Qualifiers::OCL_None:
781 // Any other property should be ignored.
782 return;
783 }
784
785 S.Diag(property->getLocation(), diag::note_property_declare);
786 if (propertyImplLoc.isValid())
787 S.Diag(propertyImplLoc, diag::note_property_synthesize);
788 }
789
790 /// setImpliedPropertyAttributeForReadOnlyProperty -
791 /// This routine evaludates life-time attributes for a 'readonly'
792 /// property with no known lifetime of its own, using backing
793 /// 'ivar's attribute, if any. If no backing 'ivar', property's
794 /// life-time is assumed 'strong'.
795 static void setImpliedPropertyAttributeForReadOnlyProperty(
796 ObjCPropertyDecl *property, ObjCIvarDecl *ivar) {
797 Qualifiers::ObjCLifetime propertyLifetime =
798 getImpliedARCOwnership(property->getPropertyAttributes(),
799 property->getType());
800 if (propertyLifetime != Qualifiers::OCL_None)
801 return;
802
803 if (!ivar) {
804 // if no backing ivar, make property 'strong'.
805 property->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_strong);
806 return;
807 }
808 // property assumes owenership of backing ivar.
809 QualType ivarType = ivar->getType();
810 Qualifiers::ObjCLifetime ivarLifetime = ivarType.getObjCLifetime();
811 if (ivarLifetime == Qualifiers::OCL_Strong)
812 property->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_strong);
813 else if (ivarLifetime == Qualifiers::OCL_Weak)
814 property->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_weak);
815 }
816
817 static bool
818 isIncompatiblePropertyAttribute(unsigned Attr1, unsigned Attr2,
819 ObjCPropertyDecl::PropertyAttributeKind Kind) {
820 return (Attr1 & Kind) != (Attr2 & Kind);
821 }
822
823 static bool areIncompatiblePropertyAttributes(unsigned Attr1, unsigned Attr2,
824 unsigned Kinds) {
825 return ((Attr1 & Kinds) != 0) != ((Attr2 & Kinds) != 0);
826 }
827
828 /// SelectPropertyForSynthesisFromProtocols - Finds the most appropriate
829 /// property declaration that should be synthesised in all of the inherited
830 /// protocols. It also diagnoses properties declared in inherited protocols with
831 /// mismatched types or attributes, since any of them can be candidate for
832 /// synthesis.
833 static ObjCPropertyDecl *
834 SelectPropertyForSynthesisFromProtocols(Sema &S, SourceLocation AtLoc,
835 ObjCInterfaceDecl *ClassDecl,
836 ObjCPropertyDecl *Property) {
837 assert(isa<ObjCProtocolDecl>(Property->getDeclContext()) &&
838 "Expected a property from a protocol");
839 ObjCInterfaceDecl::ProtocolPropertySet ProtocolSet;
840 ObjCInterfaceDecl::PropertyDeclOrder Properties;
841 for (const auto *PI : ClassDecl->all_referenced_protocols()) {
842 if (const ObjCProtocolDecl *PDecl = PI->getDefinition())
843 PDecl->collectInheritedProtocolProperties(Property, ProtocolSet,
844 Properties);
845 }
846 if (ObjCInterfaceDecl *SDecl = ClassDecl->getSuperClass()) {
847 while (SDecl) {
848 for (const auto *PI : SDecl->all_referenced_protocols()) {
849 if (const ObjCProtocolDecl *PDecl = PI->getDefinition())
850 PDecl->collectInheritedProtocolProperties(Property, ProtocolSet,
851 Properties);
852 }
853 SDecl = SDecl->getSuperClass();
854 }
855 }
856
857 if (Properties.empty())
858 return Property;
859
860 ObjCPropertyDecl *OriginalProperty = Property;
861 size_t SelectedIndex = 0;
862 for (const auto &Prop : llvm::enumerate(Properties)) {
863 // Select the 'readwrite' property if such property exists.
864 if (Property->isReadOnly() && !Prop.value()->isReadOnly()) {
865 Property = Prop.value();
866 SelectedIndex = Prop.index();
867 }
868 }
869 if (Property != OriginalProperty) {
870 // Check that the old property is compatible with the new one.
871 Properties[SelectedIndex] = OriginalProperty;
872 }
873
874 QualType RHSType = S.Context.getCanonicalType(Property->getType());
875 unsigned OriginalAttributes = Property->getPropertyAttributesAsWritten();
876 enum MismatchKind {
877 IncompatibleType = 0,
878 HasNoExpectedAttribute,
879 HasUnexpectedAttribute,
880 DifferentGetter,
881 DifferentSetter
882 };
883 // Represents a property from another protocol that conflicts with the
884 // selected declaration.
885 struct MismatchingProperty {
886 const ObjCPropertyDecl *Prop;
887 MismatchKind Kind;
888 StringRef AttributeName;
889 };
890 SmallVector<MismatchingProperty, 4> Mismatches;
891 for (ObjCPropertyDecl *Prop : Properties) {
892 // Verify the property attributes.
893 unsigned Attr = Prop->getPropertyAttributesAsWritten();
894 if (Attr != OriginalAttributes) {
895 auto Diag = [&](bool OriginalHasAttribute, StringRef AttributeName) {
896 MismatchKind Kind = OriginalHasAttribute ? HasNoExpectedAttribute
897 : HasUnexpectedAttribute;
898 Mismatches.push_back({Prop, Kind, AttributeName});
899 };
900 // The ownership might be incompatible unless the property has no explicit
901 // ownership.
902 bool HasOwnership = (Attr & (ObjCPropertyDecl::OBJC_PR_retain |
903 ObjCPropertyDecl::OBJC_PR_strong |
904 ObjCPropertyDecl::OBJC_PR_copy |
905 ObjCPropertyDecl::OBJC_PR_assign |
906 ObjCPropertyDecl::OBJC_PR_unsafe_unretained |
907 ObjCPropertyDecl::OBJC_PR_weak)) != 0;
908 if (HasOwnership &&
909 isIncompatiblePropertyAttribute(OriginalAttributes, Attr,
910 ObjCPropertyDecl::OBJC_PR_copy)) {
911 Diag(OriginalAttributes & ObjCPropertyDecl::OBJC_PR_copy, "copy");
912 continue;
913 }
914 if (HasOwnership && areIncompatiblePropertyAttributes(
915 OriginalAttributes, Attr,
916 ObjCPropertyDecl::OBJC_PR_retain |
917 ObjCPropertyDecl::OBJC_PR_strong)) {
918 Diag(OriginalAttributes & (ObjCPropertyDecl::OBJC_PR_retain |
919 ObjCPropertyDecl::OBJC_PR_strong),
920 "retain (or strong)");
921 continue;
922 }
923 if (isIncompatiblePropertyAttribute(OriginalAttributes, Attr,
924 ObjCPropertyDecl::OBJC_PR_atomic)) {
925 Diag(OriginalAttributes & ObjCPropertyDecl::OBJC_PR_atomic, "atomic");
926 continue;
927 }
928 }
929 if (Property->getGetterName() != Prop->getGetterName()) {
930 Mismatches.push_back({Prop, DifferentGetter, ""});
931 continue;
932 }
933 if (!Property->isReadOnly() && !Prop->isReadOnly() &&
934 Property->getSetterName() != Prop->getSetterName()) {
935 Mismatches.push_back({Prop, DifferentSetter, ""});
936 continue;
937 }
938 QualType LHSType = S.Context.getCanonicalType(Prop->getType());
939 if (!S.Context.propertyTypesAreCompatible(LHSType, RHSType)) {
940 bool IncompatibleObjC = false;
941 QualType ConvertedType;
942 if (!S.isObjCPointerConversion(RHSType, LHSType, ConvertedType, IncompatibleObjC)
943 || IncompatibleObjC) {
944 Mismatches.push_back({Prop, IncompatibleType, ""});
945 continue;
946 }
947 }
948 }
949
950 if (Mismatches.empty())
951 return Property;
952
953 // Diagnose incompability.
954 {
955 bool HasIncompatibleAttributes = false;
956 for (const auto &Note : Mismatches)
957 HasIncompatibleAttributes =
958 Note.Kind != IncompatibleType ? true : HasIncompatibleAttributes;
959 // Promote the warning to an error if there are incompatible attributes or
960 // incompatible types together with readwrite/readonly incompatibility.
961 auto Diag = S.Diag(Property->getLocation(),
962 Property != OriginalProperty || HasIncompatibleAttributes
963 ? diag::err_protocol_property_mismatch
964 : diag::warn_protocol_property_mismatch);
965 Diag << Mismatches[0].Kind;
966 switch (Mismatches[0].Kind) {
967 case IncompatibleType:
968 Diag << Property->getType();
969 break;
970 case HasNoExpectedAttribute:
971 case HasUnexpectedAttribute:
972 Diag << Mismatches[0].AttributeName;
973 break;
974 case DifferentGetter:
975 Diag << Property->getGetterName();
976 break;
977 case DifferentSetter:
978 Diag << Property->getSetterName();
979 break;
980 }
981 }
982 for (const auto &Note : Mismatches) {
983 auto Diag =
984 S.Diag(Note.Prop->getLocation(), diag::note_protocol_property_declare)
985 << Note.Kind;
986 switch (Note.Kind) {
987 case IncompatibleType:
988 Diag << Note.Prop->getType();
989 break;
990 case HasNoExpectedAttribute:
991 case HasUnexpectedAttribute:
992 Diag << Note.AttributeName;
993 break;
994 case DifferentGetter:
995 Diag << Note.Prop->getGetterName();
996 break;
997 case DifferentSetter:
998 Diag << Note.Prop->getSetterName();
999 break;
1000 }
1001 }
1002 if (AtLoc.isValid())
1003 S.Diag(AtLoc, diag::note_property_synthesize);
1004
1005 return Property;
1006 }
1007
1008 /// Determine whether any storage attributes were written on the property.
1009 static bool hasWrittenStorageAttribute(ObjCPropertyDecl *Prop,
1010 ObjCPropertyQueryKind QueryKind) {
1011 if (Prop->getPropertyAttributesAsWritten() & OwnershipMask) return true;
1012
1013 // If this is a readwrite property in a class extension that refines
1014 // a readonly property in the original class definition, check it as
1015 // well.
1016
1017 // If it's a readonly property, we're not interested.
1018 if (Prop->isReadOnly()) return false;
1019
1020 // Is it declared in an extension?
1021 auto Category = dyn_cast<ObjCCategoryDecl>(Prop->getDeclContext());
1022 if (!Category || !Category->IsClassExtension()) return false;
1023
1024 // Find the corresponding property in the primary class definition.
1025 auto OrigClass = Category->getClassInterface();
1026 for (auto Found : OrigClass->lookup(Prop->getDeclName())) {
1027 if (ObjCPropertyDecl *OrigProp = dyn_cast<ObjCPropertyDecl>(Found))
1028 return OrigProp->getPropertyAttributesAsWritten() & OwnershipMask;
1029 }
1030
1031 // Look through all of the protocols.
1032 for (const auto *Proto : OrigClass->all_referenced_protocols()) {
1033 if (ObjCPropertyDecl *OrigProp = Proto->FindPropertyDeclaration(
1034 Prop->getIdentifier(), QueryKind))
1035 return OrigProp->getPropertyAttributesAsWritten() & OwnershipMask;
1036 }
1037
1038 return false;
1039 }
1040
1041 /// ActOnPropertyImplDecl - This routine performs semantic checks and
1042 /// builds the AST node for a property implementation declaration; declared
1043 /// as \@synthesize or \@dynamic.
1044 ///
1045 Decl *Sema::ActOnPropertyImplDecl(Scope *S,
1046 SourceLocation AtLoc,
1047 SourceLocation PropertyLoc,
1048 bool Synthesize,
1049 IdentifierInfo *PropertyId,
1050 IdentifierInfo *PropertyIvar,
1051 SourceLocation PropertyIvarLoc,
1052 ObjCPropertyQueryKind QueryKind) {
1053 ObjCContainerDecl *ClassImpDecl =
1054 dyn_cast<ObjCContainerDecl>(CurContext);
1055 // Make sure we have a context for the property implementation declaration.
1056 if (!ClassImpDecl) {
1057 Diag(AtLoc, diag::err_missing_property_context);
1058 return nullptr;
1059 }
1060 if (PropertyIvarLoc.isInvalid())
1061 PropertyIvarLoc = PropertyLoc;
1062 SourceLocation PropertyDiagLoc = PropertyLoc;
1063 if (PropertyDiagLoc.isInvalid())
1064 PropertyDiagLoc = ClassImpDecl->getBeginLoc();
1065 ObjCPropertyDecl *property = nullptr;
1066 ObjCInterfaceDecl *IDecl = nullptr;
1067 // Find the class or category class where this property must have
1068 // a declaration.
1069 ObjCImplementationDecl *IC = nullptr;
1070 ObjCCategoryImplDecl *CatImplClass = nullptr;
1071 if ((IC = dyn_cast<ObjCImplementationDecl>(ClassImpDecl))) {
1072 IDecl = IC->getClassInterface();
1073 // We always synthesize an interface for an implementation
1074 // without an interface decl. So, IDecl is always non-zero.
1075 assert(IDecl &&
1076 "ActOnPropertyImplDecl - @implementation without @interface");
1077
1078 // Look for this property declaration in the @implementation's @interface
1079 property = IDecl->FindPropertyDeclaration(PropertyId, QueryKind);
1080 if (!property) {
1081 Diag(PropertyLoc, diag::err_bad_property_decl) << IDecl->getDeclName();
1082 return nullptr;
1083 }
1084 if (property->isClassProperty() && Synthesize) {
1085 Diag(PropertyLoc, diag::err_synthesize_on_class_property) << PropertyId;
1086 return nullptr;
1087 }
1088 unsigned PIkind = property->getPropertyAttributesAsWritten();
1089 if ((PIkind & (ObjCPropertyDecl::OBJC_PR_atomic |
1090 ObjCPropertyDecl::OBJC_PR_nonatomic) ) == 0) {
1091 if (AtLoc.isValid())
1092 Diag(AtLoc, diag::warn_implicit_atomic_property);
1093 else
1094 Diag(IC->getLocation(), diag::warn_auto_implicit_atomic_property);
1095 Diag(property->getLocation(), diag::note_property_declare);
1096 }
1097
1098 if (const ObjCCategoryDecl *CD =
1099 dyn_cast<ObjCCategoryDecl>(property->getDeclContext())) {
1100 if (!CD->IsClassExtension()) {
1101 Diag(PropertyLoc, diag::err_category_property) << CD->getDeclName();
1102 Diag(property->getLocation(), diag::note_property_declare);
1103 return nullptr;
1104 }
1105 }
1106 if (Synthesize&&
1107 (PIkind & ObjCPropertyDecl::OBJC_PR_readonly) &&
1108 property->hasAttr<IBOutletAttr>() &&
1109 !AtLoc.isValid()) {
1110 bool ReadWriteProperty = false;
1111 // Search into the class extensions and see if 'readonly property is
1112 // redeclared 'readwrite', then no warning is to be issued.
1113 for (auto *Ext : IDecl->known_extensions()) {
1114 DeclContext::lookup_result R = Ext->lookup(property->getDeclName());
1115 if (!R.empty())
1116 if (ObjCPropertyDecl *ExtProp = dyn_cast<ObjCPropertyDecl>(R[0])) {
1117 PIkind = ExtProp->getPropertyAttributesAsWritten();
1118 if (PIkind & ObjCPropertyDecl::OBJC_PR_readwrite) {
1119 ReadWriteProperty = true;
1120 break;
1121 }
1122 }
1123 }
1124
1125 if (!ReadWriteProperty) {
1126 Diag(property->getLocation(), diag::warn_auto_readonly_iboutlet_property)
1127 << property;
1128 SourceLocation readonlyLoc;
1129 if (LocPropertyAttribute(Context, "readonly",
1130 property->getLParenLoc(), readonlyLoc)) {
1131 SourceLocation endLoc =
1132 readonlyLoc.getLocWithOffset(strlen("readonly")-1);
1133 SourceRange ReadonlySourceRange(readonlyLoc, endLoc);
1134 Diag(property->getLocation(),
1135 diag::note_auto_readonly_iboutlet_fixup_suggest) <<
1136 FixItHint::CreateReplacement(ReadonlySourceRange, "readwrite");
1137 }
1138 }
1139 }
1140 if (Synthesize && isa<ObjCProtocolDecl>(property->getDeclContext()))
1141 property = SelectPropertyForSynthesisFromProtocols(*this, AtLoc, IDecl,
1142 property);
1143
1144 } else if ((CatImplClass = dyn_cast<ObjCCategoryImplDecl>(ClassImpDecl))) {
1145 if (Synthesize) {
1146 Diag(AtLoc, diag::err_synthesize_category_decl);
1147 return nullptr;
1148 }
1149 IDecl = CatImplClass->getClassInterface();
1150 if (!IDecl) {
1151 Diag(AtLoc, diag::err_missing_property_interface);
1152 return nullptr;
1153 }
1154 ObjCCategoryDecl *Category =
1155 IDecl->FindCategoryDeclaration(CatImplClass->getIdentifier());
1156
1157 // If category for this implementation not found, it is an error which
1158 // has already been reported eralier.
1159 if (!Category)
1160 return nullptr;
1161 // Look for this property declaration in @implementation's category
1162 property = Category->FindPropertyDeclaration(PropertyId, QueryKind);
1163 if (!property) {
1164 Diag(PropertyLoc, diag::err_bad_category_property_decl)
1165 << Category->getDeclName();
1166 return nullptr;
1167 }
1168 } else {
1169 Diag(AtLoc, diag::err_bad_property_context);
1170 return nullptr;
1171 }
1172 ObjCIvarDecl *Ivar = nullptr;
1173 bool CompleteTypeErr = false;
1174 bool compat = true;
1175 // Check that we have a valid, previously declared ivar for @synthesize
1176 if (Synthesize) {
1177 // @synthesize
1178 if (!PropertyIvar)
1179 PropertyIvar = PropertyId;
1180 // Check that this is a previously declared 'ivar' in 'IDecl' interface
1181 ObjCInterfaceDecl *ClassDeclared;
1182 Ivar = IDecl->lookupInstanceVariable(PropertyIvar, ClassDeclared);
1183 QualType PropType = property->getType();
1184 QualType PropertyIvarType = PropType.getNonReferenceType();
1185
1186 if (RequireCompleteType(PropertyDiagLoc, PropertyIvarType,
1187 diag::err_incomplete_synthesized_property,
1188 property->getDeclName())) {
1189 Diag(property->getLocation(), diag::note_property_declare);
1190 CompleteTypeErr = true;
1191 }
1192
1193 if (getLangOpts().ObjCAutoRefCount &&
1194 (property->getPropertyAttributesAsWritten() &
1195 ObjCPropertyDecl::OBJC_PR_readonly) &&
1196 PropertyIvarType->isObjCRetainableType()) {
1197 setImpliedPropertyAttributeForReadOnlyProperty(property, Ivar);
1198 }
1199
1200 ObjCPropertyDecl::PropertyAttributeKind kind
1201 = property->getPropertyAttributes();
1202
1203 bool isARCWeak = false;
1204 if (kind & ObjCPropertyDecl::OBJC_PR_weak) {
1205 // Add GC __weak to the ivar type if the property is weak.
1206 if (getLangOpts().getGC() != LangOptions::NonGC) {
1207 assert(!getLangOpts().ObjCAutoRefCount);
1208 if (PropertyIvarType.isObjCGCStrong()) {
1209 Diag(PropertyDiagLoc, diag::err_gc_weak_property_strong_type);
1210 Diag(property->getLocation(), diag::note_property_declare);
1211 } else {
1212 PropertyIvarType =
1213 Context.getObjCGCQualType(PropertyIvarType, Qualifiers::Weak);
1214 }
1215
1216 // Otherwise, check whether ARC __weak is enabled and works with
1217 // the property type.
1218 } else {
1219 if (!getLangOpts().ObjCWeak) {
1220 // Only complain here when synthesizing an ivar.
1221 if (!Ivar) {
1222 Diag(PropertyDiagLoc,
1223 getLangOpts().ObjCWeakRuntime
1224 ? diag::err_synthesizing_arc_weak_property_disabled
1225 : diag::err_synthesizing_arc_weak_property_no_runtime);
1226 Diag(property->getLocation(), diag::note_property_declare);
1227 }
1228 CompleteTypeErr = true; // suppress later diagnostics about the ivar
1229 } else {
1230 isARCWeak = true;
1231 if (const ObjCObjectPointerType *ObjT =
1232 PropertyIvarType->getAs<ObjCObjectPointerType>()) {
1233 const ObjCInterfaceDecl *ObjI = ObjT->getInterfaceDecl();
1234 if (ObjI && ObjI->isArcWeakrefUnavailable()) {
1235 Diag(property->getLocation(),
1236 diag::err_arc_weak_unavailable_property)
1237 << PropertyIvarType;
1238 Diag(ClassImpDecl->getLocation(), diag::note_implemented_by_class)
1239 << ClassImpDecl->getName();
1240 }
1241 }
1242 }
1243 }
1244 }
1245
1246 if (AtLoc.isInvalid()) {
1247 // Check when default synthesizing a property that there is
1248 // an ivar matching property name and issue warning; since this
1249 // is the most common case of not using an ivar used for backing
1250 // property in non-default synthesis case.
1251 ObjCInterfaceDecl *ClassDeclared=nullptr;
1252 ObjCIvarDecl *originalIvar =
1253 IDecl->lookupInstanceVariable(property->getIdentifier(),
1254 ClassDeclared);
1255 if (originalIvar) {
1256 Diag(PropertyDiagLoc,
1257 diag::warn_autosynthesis_property_ivar_match)
1258 << PropertyId << (Ivar == nullptr) << PropertyIvar
1259 << originalIvar->getIdentifier();
1260 Diag(property->getLocation(), diag::note_property_declare);
1261 Diag(originalIvar->getLocation(), diag::note_ivar_decl);
1262 }
1263 }
1264
1265 if (!Ivar) {
1266 // In ARC, give the ivar a lifetime qualifier based on the
1267 // property attributes.
1268 if ((getLangOpts().ObjCAutoRefCount || isARCWeak) &&
1269 !PropertyIvarType.getObjCLifetime() &&
1270 PropertyIvarType->isObjCRetainableType()) {
1271
1272 // It's an error if we have to do this and the user didn't
1273 // explicitly write an ownership attribute on the property.
1274 if (!hasWrittenStorageAttribute(property, QueryKind) &&
1275 !(kind & ObjCPropertyDecl::OBJC_PR_strong)) {
1276 Diag(PropertyDiagLoc,
1277 diag::err_arc_objc_property_default_assign_on_object);
1278 Diag(property->getLocation(), diag::note_property_declare);
1279 } else {
1280 Qualifiers::ObjCLifetime lifetime =
1281 getImpliedARCOwnership(kind, PropertyIvarType);
1282 assert(lifetime && "no lifetime for property?");
1283
1284 Qualifiers qs;
1285 qs.addObjCLifetime(lifetime);
1286 PropertyIvarType = Context.getQualifiedType(PropertyIvarType, qs);
1287 }
1288 }
1289
1290 Ivar = ObjCIvarDecl::Create(Context, ClassImpDecl,
1291 PropertyIvarLoc,PropertyIvarLoc, PropertyIvar,
1292 PropertyIvarType, /*Dinfo=*/nullptr,
1293 ObjCIvarDecl::Private,
1294 (Expr *)nullptr, true);
1295 if (RequireNonAbstractType(PropertyIvarLoc,
1296 PropertyIvarType,
1297 diag::err_abstract_type_in_decl,
1298 AbstractSynthesizedIvarType)) {
1299 Diag(property->getLocation(), diag::note_property_declare);
1300 // An abstract type is as bad as an incomplete type.
1301 CompleteTypeErr = true;
1302 }
1303 if (!CompleteTypeErr) {
1304 const RecordType *RecordTy = PropertyIvarType->getAs<RecordType>();
1305 if (RecordTy && RecordTy->getDecl()->hasFlexibleArrayMember()) {
1306 Diag(PropertyIvarLoc, diag::err_synthesize_variable_sized_ivar)
1307 << PropertyIvarType;
1308 CompleteTypeErr = true; // suppress later diagnostics about the ivar
1309 }
1310 }
1311 if (CompleteTypeErr)
1312 Ivar->setInvalidDecl();
1313 ClassImpDecl->addDecl(Ivar);
1314 IDecl->makeDeclVisibleInContext(Ivar);
1315
1316 if (getLangOpts().ObjCRuntime.isFragile())
1317 Diag(PropertyDiagLoc, diag::err_missing_property_ivar_decl)
1318 << PropertyId;
1319 // Note! I deliberately want it to fall thru so, we have a
1320 // a property implementation and to avoid future warnings.
1321 } else if (getLangOpts().ObjCRuntime.isNonFragile() &&
1322 !declaresSameEntity(ClassDeclared, IDecl)) {
1323 Diag(PropertyDiagLoc, diag::err_ivar_in_superclass_use)
1324 << property->getDeclName() << Ivar->getDeclName()
1325 << ClassDeclared->getDeclName();
1326 Diag(Ivar->getLocation(), diag::note_previous_access_declaration)
1327 << Ivar << Ivar->getName();
1328 // Note! I deliberately want it to fall thru so more errors are caught.
1329 }
1330 property->setPropertyIvarDecl(Ivar);
1331
1332 QualType IvarType = Context.getCanonicalType(Ivar->getType());
1333
1334 // Check that type of property and its ivar are type compatible.
1335 if (!Context.hasSameType(PropertyIvarType, IvarType)) {
1336 if (isa<ObjCObjectPointerType>(PropertyIvarType)
1337 && isa<ObjCObjectPointerType>(IvarType))
1338 compat =
1339 Context.canAssignObjCInterfaces(
1340 PropertyIvarType->getAs<ObjCObjectPointerType>(),
1341 IvarType->getAs<ObjCObjectPointerType>());
1342 else {
1343 compat = (CheckAssignmentConstraints(PropertyIvarLoc, PropertyIvarType,
1344 IvarType)
1345 == Compatible);
1346 }
1347 if (!compat) {
1348 Diag(PropertyDiagLoc, diag::err_property_ivar_type)
1349 << property->getDeclName() << PropType
1350 << Ivar->getDeclName() << IvarType;
1351 Diag(Ivar->getLocation(), diag::note_ivar_decl);
1352 // Note! I deliberately want it to fall thru so, we have a
1353 // a property implementation and to avoid future warnings.
1354 }
1355 else {
1356 // FIXME! Rules for properties are somewhat different that those
1357 // for assignments. Use a new routine to consolidate all cases;
1358 // specifically for property redeclarations as well as for ivars.
1359 QualType lhsType =Context.getCanonicalType(PropertyIvarType).getUnqualifiedType();
1360 QualType rhsType =Context.getCanonicalType(IvarType).getUnqualifiedType();
1361 if (lhsType != rhsType &&
1362 lhsType->isArithmeticType()) {
1363 Diag(PropertyDiagLoc, diag::err_property_ivar_type)
1364 << property->getDeclName() << PropType
1365 << Ivar->getDeclName() << IvarType;
1366 Diag(Ivar->getLocation(), diag::note_ivar_decl);
1367 // Fall thru - see previous comment
1368 }
1369 }
1370 // __weak is explicit. So it works on Canonical type.
1371 if ((PropType.isObjCGCWeak() && !IvarType.isObjCGCWeak() &&
1372 getLangOpts().getGC() != LangOptions::NonGC)) {
1373 Diag(PropertyDiagLoc, diag::err_weak_property)
1374 << property->getDeclName() << Ivar->getDeclName();
1375 Diag(Ivar->getLocation(), diag::note_ivar_decl);
1376 // Fall thru - see previous comment
1377 }
1378 // Fall thru - see previous comment
1379 if ((property->getType()->isObjCObjectPointerType() ||
1380 PropType.isObjCGCStrong()) && IvarType.isObjCGCWeak() &&
1381 getLangOpts().getGC() != LangOptions::NonGC) {
1382 Diag(PropertyDiagLoc, diag::err_strong_property)
1383 << property->getDeclName() << Ivar->getDeclName();
1384 // Fall thru - see previous comment
1385 }
1386 }
1387 if (getLangOpts().ObjCAutoRefCount || isARCWeak ||
1388 Ivar->getType().getObjCLifetime())
1389 checkARCPropertyImpl(*this, PropertyLoc, property, Ivar);
1390 } else if (PropertyIvar)
1391 // @dynamic
1392 Diag(PropertyDiagLoc, diag::err_dynamic_property_ivar_decl);
1393
1394 assert (property && "ActOnPropertyImplDecl - property declaration missing");
1395 ObjCPropertyImplDecl *PIDecl =
1396 ObjCPropertyImplDecl::Create(Context, CurContext, AtLoc, PropertyLoc,
1397 property,
1398 (Synthesize ?
1399 ObjCPropertyImplDecl::Synthesize
1400 : ObjCPropertyImplDecl::Dynamic),
1401 Ivar, PropertyIvarLoc);
1402
1403 if (CompleteTypeErr || !compat)
1404 PIDecl->setInvalidDecl();
1405
1406 if (ObjCMethodDecl *getterMethod = property->getGetterMethodDecl()) {
1407 getterMethod->createImplicitParams(Context, IDecl);
1408 if (getLangOpts().CPlusPlus && Synthesize && !CompleteTypeErr &&
1409 Ivar->getType()->isRecordType()) {
1410 // For Objective-C++, need to synthesize the AST for the IVAR object to be
1411 // returned by the getter as it must conform to C++'s copy-return rules.
1412 // FIXME. Eventually we want to do this for Objective-C as well.
1413 SynthesizedFunctionScope Scope(*this, getterMethod);
1414 ImplicitParamDecl *SelfDecl = getterMethod->getSelfDecl();
1415 DeclRefExpr *SelfExpr = new (Context)
1416 DeclRefExpr(Context, SelfDecl, false, SelfDecl->getType(), VK_LValue,
1417 PropertyDiagLoc);
1418 MarkDeclRefReferenced(SelfExpr);
1419 Expr *LoadSelfExpr =
1420 ImplicitCastExpr::Create(Context, SelfDecl->getType(),
1421 CK_LValueToRValue, SelfExpr, nullptr,
1422 VK_RValue);
1423 Expr *IvarRefExpr =
1424 new (Context) ObjCIvarRefExpr(Ivar,
1425 Ivar->getUsageType(SelfDecl->getType()),
1426 PropertyDiagLoc,
1427 Ivar->getLocation(),
1428 LoadSelfExpr, true, true);
1429 ExprResult Res = PerformCopyInitialization(
1430 InitializedEntity::InitializeResult(PropertyDiagLoc,
1431 getterMethod->getReturnType(),
1432 /*NRVO=*/false),
1433 PropertyDiagLoc, IvarRefExpr);
1434 if (!Res.isInvalid()) {
1435 Expr *ResExpr = Res.getAs<Expr>();
1436 if (ResExpr)
1437 ResExpr = MaybeCreateExprWithCleanups(ResExpr);
1438 PIDecl->setGetterCXXConstructor(ResExpr);
1439 }
1440 }
1441 if (property->hasAttr<NSReturnsNotRetainedAttr>() &&
1442 !getterMethod->hasAttr<NSReturnsNotRetainedAttr>()) {
1443 Diag(getterMethod->getLocation(),
1444 diag::warn_property_getter_owning_mismatch);
1445 Diag(property->getLocation(), diag::note_property_declare);
1446 }
1447 if (getLangOpts().ObjCAutoRefCount && Synthesize)
1448 switch (getterMethod->getMethodFamily()) {
1449 case OMF_retain:
1450 case OMF_retainCount:
1451 case OMF_release:
1452 case OMF_autorelease:
1453 Diag(getterMethod->getLocation(), diag::err_arc_illegal_method_def)
1454 << 1 << getterMethod->getSelector();
1455 break;
1456 default:
1457 break;
1458 }
1459 }
1460 if (ObjCMethodDecl *setterMethod = property->getSetterMethodDecl()) {
1461 setterMethod->createImplicitParams(Context, IDecl);
1462 if (getLangOpts().CPlusPlus && Synthesize && !CompleteTypeErr &&
1463 Ivar->getType()->isRecordType()) {
1464 // FIXME. Eventually we want to do this for Objective-C as well.
1465 SynthesizedFunctionScope Scope(*this, setterMethod);
1466 ImplicitParamDecl *SelfDecl = setterMethod->getSelfDecl();
1467 DeclRefExpr *SelfExpr = new (Context)
1468 DeclRefExpr(Context, SelfDecl, false, SelfDecl->getType(), VK_LValue,
1469 PropertyDiagLoc);
1470 MarkDeclRefReferenced(SelfExpr);
1471 Expr *LoadSelfExpr =
1472 ImplicitCastExpr::Create(Context, SelfDecl->getType(),
1473 CK_LValueToRValue, SelfExpr, nullptr,
1474 VK_RValue);
1475 Expr *lhs =
1476 new (Context) ObjCIvarRefExpr(Ivar,
1477 Ivar->getUsageType(SelfDecl->getType()),
1478 PropertyDiagLoc,
1479 Ivar->getLocation(),
1480 LoadSelfExpr, true, true);
1481 ObjCMethodDecl::param_iterator P = setterMethod->param_begin();
1482 ParmVarDecl *Param = (*P);
1483 QualType T = Param->getType().getNonReferenceType();
1484 DeclRefExpr *rhs = new (Context)
1485 DeclRefExpr(Context, Param, false, T, VK_LValue, PropertyDiagLoc);
1486 MarkDeclRefReferenced(rhs);
1487 ExprResult Res = BuildBinOp(S, PropertyDiagLoc,
1488 BO_Assign, lhs, rhs);
1489 if (property->getPropertyAttributes() &
1490 ObjCPropertyDecl::OBJC_PR_atomic) {
1491 Expr *callExpr = Res.getAs<Expr>();
1492 if (const CXXOperatorCallExpr *CXXCE =
1493 dyn_cast_or_null<CXXOperatorCallExpr>(callExpr))
1494 if (const FunctionDecl *FuncDecl = CXXCE->getDirectCallee())
1495 if (!FuncDecl->isTrivial())
1496 if (property->getType()->isReferenceType()) {
1497 Diag(PropertyDiagLoc,
1498 diag::err_atomic_property_nontrivial_assign_op)
1499 << property->getType();
1500 Diag(FuncDecl->getBeginLoc(), diag::note_callee_decl)
1501 << FuncDecl;
1502 }
1503 }
1504 PIDecl->setSetterCXXAssignment(Res.getAs<Expr>());
1505 }
1506 }
1507
1508 if (IC) {
1509 if (Synthesize)
1510 if (ObjCPropertyImplDecl *PPIDecl =
1511 IC->FindPropertyImplIvarDecl(PropertyIvar)) {
1512 Diag(PropertyLoc, diag::err_duplicate_ivar_use)
1513 << PropertyId << PPIDecl->getPropertyDecl()->getIdentifier()
1514 << PropertyIvar;
1515 Diag(PPIDecl->getLocation(), diag::note_previous_use);
1516 }
1517
1518 if (ObjCPropertyImplDecl *PPIDecl
1519 = IC->FindPropertyImplDecl(PropertyId, QueryKind)) {
1520 Diag(PropertyLoc, diag::err_property_implemented) << PropertyId;
1521 Diag(PPIDecl->getLocation(), diag::note_previous_declaration);
1522 return nullptr;
1523 }
1524 IC->addPropertyImplementation(PIDecl);
1525 if (getLangOpts().ObjCDefaultSynthProperties &&
1526 getLangOpts().ObjCRuntime.isNonFragile() &&
1527 !IDecl->isObjCRequiresPropertyDefs()) {
1528 // Diagnose if an ivar was lazily synthesdized due to a previous
1529 // use and if 1) property is @dynamic or 2) property is synthesized
1530 // but it requires an ivar of different name.
1531 ObjCInterfaceDecl *ClassDeclared=nullptr;
1532 ObjCIvarDecl *Ivar = nullptr;
1533 if (!Synthesize)
1534 Ivar = IDecl->lookupInstanceVariable(PropertyId, ClassDeclared);
1535 else {
1536 if (PropertyIvar && PropertyIvar != PropertyId)
1537 Ivar = IDecl->lookupInstanceVariable(PropertyId, ClassDeclared);
1538 }
1539 // Issue diagnostics only if Ivar belongs to current class.
1540 if (Ivar && Ivar->getSynthesize() &&
1541 declaresSameEntity(IC->getClassInterface(), ClassDeclared)) {
1542 Diag(Ivar->getLocation(), diag::err_undeclared_var_use)
1543 << PropertyId;
1544 Ivar->setInvalidDecl();
1545 }
1546 }
1547 } else {
1548 if (Synthesize)
1549 if (ObjCPropertyImplDecl *PPIDecl =
1550 CatImplClass->FindPropertyImplIvarDecl(PropertyIvar)) {
1551 Diag(PropertyDiagLoc, diag::err_duplicate_ivar_use)
1552 << PropertyId << PPIDecl->getPropertyDecl()->getIdentifier()
1553 << PropertyIvar;
1554 Diag(PPIDecl->getLocation(), diag::note_previous_use);
1555 }
1556
1557 if (ObjCPropertyImplDecl *PPIDecl =
1558 CatImplClass->FindPropertyImplDecl(PropertyId, QueryKind)) {
1559 Diag(PropertyDiagLoc, diag::err_property_implemented) << PropertyId;
1560 Diag(PPIDecl->getLocation(), diag::note_previous_declaration);
1561 return nullptr;
1562 }
1563 CatImplClass->addPropertyImplementation(PIDecl);
1564 }
1565
1566 return PIDecl;
1567 }
1568
1569 //===----------------------------------------------------------------------===//
1570 // Helper methods.
1571 //===----------------------------------------------------------------------===//
1572
1573 /// DiagnosePropertyMismatch - Compares two properties for their
1574 /// attributes and types and warns on a variety of inconsistencies.
1575 ///
1576 void
1577 Sema::DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
1578 ObjCPropertyDecl *SuperProperty,
1579 const IdentifierInfo *inheritedName,
1580 bool OverridingProtocolProperty) {
1581 ObjCPropertyDecl::PropertyAttributeKind CAttr =
1582 Property->getPropertyAttributes();
1583 ObjCPropertyDecl::PropertyAttributeKind SAttr =
1584 SuperProperty->getPropertyAttributes();
1585
1586 // We allow readonly properties without an explicit ownership
1587 // (assign/unsafe_unretained/weak/retain/strong/copy) in super class
1588 // to be overridden by a property with any explicit ownership in the subclass.
1589 if (!OverridingProtocolProperty &&
1590 !getOwnershipRule(SAttr) && getOwnershipRule(CAttr))
1591 ;
1592 else {
1593 if ((CAttr & ObjCPropertyDecl::OBJC_PR_readonly)
1594 && (SAttr & ObjCPropertyDecl::OBJC_PR_readwrite))
1595 Diag(Property->getLocation(), diag::warn_readonly_property)
1596 << Property->getDeclName() << inheritedName;
1597 if ((CAttr & ObjCPropertyDecl::OBJC_PR_copy)
1598 != (SAttr & ObjCPropertyDecl::OBJC_PR_copy))
1599 Diag(Property->getLocation(), diag::warn_property_attribute)
1600 << Property->getDeclName() << "copy" << inheritedName;
1601 else if (!(SAttr & ObjCPropertyDecl::OBJC_PR_readonly)){
1602 unsigned CAttrRetain =
1603 (CAttr &
1604 (ObjCPropertyDecl::OBJC_PR_retain | ObjCPropertyDecl::OBJC_PR_strong));
1605 unsigned SAttrRetain =
1606 (SAttr &
1607 (ObjCPropertyDecl::OBJC_PR_retain | ObjCPropertyDecl::OBJC_PR_strong));
1608 bool CStrong = (CAttrRetain != 0);
1609 bool SStrong = (SAttrRetain != 0);
1610 if (CStrong != SStrong)
1611 Diag(Property->getLocation(), diag::warn_property_attribute)
1612 << Property->getDeclName() << "retain (or strong)" << inheritedName;
1613 }
1614 }
1615
1616 // Check for nonatomic; note that nonatomic is effectively
1617 // meaningless for readonly properties, so don't diagnose if the
1618 // atomic property is 'readonly'.
1619 checkAtomicPropertyMismatch(*this, SuperProperty, Property, false);
1620 // Readonly properties from protocols can be implemented as "readwrite"
1621 // with a custom setter name.
1622 if (Property->getSetterName() != SuperProperty->getSetterName() &&
1623 !(SuperProperty->isReadOnly() &&
1624 isa<ObjCProtocolDecl>(SuperProperty->getDeclContext()))) {
1625 Diag(Property->getLocation(), diag::warn_property_attribute)
1626 << Property->getDeclName() << "setter" << inheritedName;
1627 Diag(SuperProperty->getLocation(), diag::note_property_declare);
1628 }
1629 if (Property->getGetterName() != SuperProperty->getGetterName()) {
1630 Diag(Property->getLocation(), diag::warn_property_attribute)
1631 << Property->getDeclName() << "getter" << inheritedName;
1632 Diag(SuperProperty->getLocation(), diag::note_property_declare);
1633 }
1634
1635 QualType LHSType =
1636 Context.getCanonicalType(SuperProperty->getType());
1637 QualType RHSType =
1638 Context.getCanonicalType(Property->getType());
1639
1640 if (!Context.propertyTypesAreCompatible(LHSType, RHSType)) {
1641 // Do cases not handled in above.
1642 // FIXME. For future support of covariant property types, revisit this.
1643 bool IncompatibleObjC = false;
1644 QualType ConvertedType;
1645 if (!isObjCPointerConversion(RHSType, LHSType,
1646 ConvertedType, IncompatibleObjC) ||
1647 IncompatibleObjC) {
1648 Diag(Property->getLocation(), diag::warn_property_types_are_incompatible)
1649 << Property->getType() << SuperProperty->getType() << inheritedName;
1650 Diag(SuperProperty->getLocation(), diag::note_property_declare);
1651 }
1652 }
1653 }
1654
1655 bool Sema::DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *property,
1656 ObjCMethodDecl *GetterMethod,
1657 SourceLocation Loc) {
1658 if (!GetterMethod)
1659 return false;
1660 QualType GetterType = GetterMethod->getReturnType().getNonReferenceType();
1661 QualType PropertyRValueType =
1662 property->getType().getNonReferenceType().getAtomicUnqualifiedType();
1663 bool compat = Context.hasSameType(PropertyRValueType, GetterType);
1664 if (!compat) {
1665 const ObjCObjectPointerType *propertyObjCPtr = nullptr;
1666 const ObjCObjectPointerType *getterObjCPtr = nullptr;
1667 if ((propertyObjCPtr =
1668 PropertyRValueType->getAs<ObjCObjectPointerType>()) &&
1669 (getterObjCPtr = GetterType->getAs<ObjCObjectPointerType>()))
1670 compat = Context.canAssignObjCInterfaces(getterObjCPtr, propertyObjCPtr);
1671 else if (CheckAssignmentConstraints(Loc, GetterType, PropertyRValueType)
1672 != Compatible) {
1673 Diag(Loc, diag::err_property_accessor_type)
1674 << property->getDeclName() << PropertyRValueType
1675 << GetterMethod->getSelector() << GetterType;
1676 Diag(GetterMethod->getLocation(), diag::note_declared_at);
1677 return true;
1678 } else {
1679 compat = true;
1680 QualType lhsType = Context.getCanonicalType(PropertyRValueType);
1681 QualType rhsType =Context.getCanonicalType(GetterType).getUnqualifiedType();
1682 if (lhsType != rhsType && lhsType->isArithmeticType())
1683 compat = false;
1684 }
1685 }
1686
1687 if (!compat) {
1688 Diag(Loc, diag::warn_accessor_property_type_mismatch)
1689 << property->getDeclName()
1690 << GetterMethod->getSelector();
1691 Diag(GetterMethod->getLocation(), diag::note_declared_at);
1692 return true;
1693 }
1694
1695 return false;
1696 }
1697
1698 /// CollectImmediateProperties - This routine collects all properties in
1699 /// the class and its conforming protocols; but not those in its super class.
1700 static void
1701 CollectImmediateProperties(ObjCContainerDecl *CDecl,
1702 ObjCContainerDecl::PropertyMap &PropMap,
1703 ObjCContainerDecl::PropertyMap &SuperPropMap,
1704 bool CollectClassPropsOnly = false,
1705 bool IncludeProtocols = true) {
1706 if (ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(CDecl)) {
1707 for (auto *Prop : IDecl->properties()) {
1708 if (CollectClassPropsOnly && !Prop->isClassProperty())
1709 continue;
1710 PropMap[std::make_pair(Prop->getIdentifier(), Prop->isClassProperty())] =
1711 Prop;
1712 }
1713
1714 // Collect the properties from visible extensions.
1715 for (auto *Ext : IDecl->visible_extensions())
1716 CollectImmediateProperties(Ext, PropMap, SuperPropMap,
1717 CollectClassPropsOnly, IncludeProtocols);
1718
1719 if (IncludeProtocols) {
1720 // Scan through class's protocols.
1721 for (auto *PI : IDecl->all_referenced_protocols())
1722 CollectImmediateProperties(PI, PropMap, SuperPropMap,
1723 CollectClassPropsOnly);
1724 }
1725 }
1726 if (ObjCCategoryDecl *CATDecl = dyn_cast<ObjCCategoryDecl>(CDecl)) {
1727 for (auto *Prop : CATDecl->properties()) {
1728 if (CollectClassPropsOnly && !Prop->isClassProperty())
1729 continue;
1730 PropMap[std::make_pair(Prop->getIdentifier(), Prop->isClassProperty())] =
1731 Prop;
1732 }
1733 if (IncludeProtocols) {
1734 // Scan through class's protocols.
1735 for (auto *PI : CATDecl->protocols())
1736 CollectImmediateProperties(PI, PropMap, SuperPropMap,
1737 CollectClassPropsOnly);
1738 }
1739 }
1740 else if (ObjCProtocolDecl *PDecl = dyn_cast<ObjCProtocolDecl>(CDecl)) {
1741 for (auto *Prop : PDecl->properties()) {
1742 if (CollectClassPropsOnly && !Prop->isClassProperty())
1743 continue;
1744 ObjCPropertyDecl *PropertyFromSuper =
1745 SuperPropMap[std::make_pair(Prop->getIdentifier(),
1746 Prop->isClassProperty())];
1747 // Exclude property for protocols which conform to class's super-class,
1748 // as super-class has to implement the property.
1749 if (!PropertyFromSuper ||
1750 PropertyFromSuper->getIdentifier() != Prop->getIdentifier()) {
1751 ObjCPropertyDecl *&PropEntry =
1752 PropMap[std::make_pair(Prop->getIdentifier(),
1753 Prop->isClassProperty())];
1754 if (!PropEntry)
1755 PropEntry = Prop;
1756 }
1757 }
1758 // Scan through protocol's protocols.
1759 for (auto *PI : PDecl->protocols())
1760 CollectImmediateProperties(PI, PropMap, SuperPropMap,
1761 CollectClassPropsOnly);
1762 }
1763 }
1764
1765 /// CollectSuperClassPropertyImplementations - This routine collects list of
1766 /// properties to be implemented in super class(s) and also coming from their
1767 /// conforming protocols.
1768 static void CollectSuperClassPropertyImplementations(ObjCInterfaceDecl *CDecl,
1769 ObjCInterfaceDecl::PropertyMap &PropMap) {
1770 if (ObjCInterfaceDecl *SDecl = CDecl->getSuperClass()) {
1771 ObjCInterfaceDecl::PropertyDeclOrder PO;
1772 while (SDecl) {
1773 SDecl->collectPropertiesToImplement(PropMap, PO);
1774 SDecl = SDecl->getSuperClass();
1775 }
1776 }
1777 }
1778
1779 /// IvarBacksCurrentMethodAccessor - This routine returns 'true' if 'IV' is
1780 /// an ivar synthesized for 'Method' and 'Method' is a property accessor
1781 /// declared in class 'IFace'.
1782 bool
1783 Sema::IvarBacksCurrentMethodAccessor(ObjCInterfaceDecl *IFace,
1784 ObjCMethodDecl *Method, ObjCIvarDecl *IV) {
1785 if (!IV->getSynthesize())
1786 return false;
1787 ObjCMethodDecl *IMD = IFace->lookupMethod(Method->getSelector(),
1788 Method->isInstanceMethod());
1789 if (!IMD || !IMD->isPropertyAccessor())
1790 return false;
1791
1792 // look up a property declaration whose one of its accessors is implemented
1793 // by this method.
1794 for (const auto *Property : IFace->instance_properties()) {
1795 if ((Property->getGetterName() == IMD->getSelector() ||
1796 Property->getSetterName() == IMD->getSelector()) &&
1797 (Property->getPropertyIvarDecl() == IV))
1798 return true;
1799 }
1800 // Also look up property declaration in class extension whose one of its
1801 // accessors is implemented by this method.
1802 for (const auto *Ext : IFace->known_extensions())
1803 for (const auto *Property : Ext->instance_properties())
1804 if ((Property->getGetterName() == IMD->getSelector() ||
1805 Property->getSetterName() == IMD->getSelector()) &&
1806 (Property->getPropertyIvarDecl() == IV))
1807 return true;
1808 return false;
1809 }
1810
1811 static bool SuperClassImplementsProperty(ObjCInterfaceDecl *IDecl,
1812 ObjCPropertyDecl *Prop) {
1813 bool SuperClassImplementsGetter = false;
1814 bool SuperClassImplementsSetter = false;
1815 if (Prop->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_readonly)
1816 SuperClassImplementsSetter = true;
1817
1818 while (IDecl->getSuperClass()) {
1819 ObjCInterfaceDecl *SDecl = IDecl->getSuperClass();
1820 if (!SuperClassImplementsGetter && SDecl->getInstanceMethod(Prop->getGetterName()))
1821 SuperClassImplementsGetter = true;
1822
1823 if (!SuperClassImplementsSetter && SDecl->getInstanceMethod(Prop->getSetterName()))
1824 SuperClassImplementsSetter = true;
1825 if (SuperClassImplementsGetter && SuperClassImplementsSetter)
1826 return true;
1827 IDecl = IDecl->getSuperClass();
1828 }
1829 return false;
1830 }
1831
1832 /// Default synthesizes all properties which must be synthesized
1833 /// in class's \@implementation.
1834 void Sema::DefaultSynthesizeProperties(Scope *S, ObjCImplDecl *IMPDecl,
1835 ObjCInterfaceDecl *IDecl,
1836 SourceLocation AtEnd) {
1837 ObjCInterfaceDecl::PropertyMap PropMap;
1838 ObjCInterfaceDecl::PropertyDeclOrder PropertyOrder;
1839 IDecl->collectPropertiesToImplement(PropMap, PropertyOrder);
1840 if (PropMap.empty())
1841 return;
1842 ObjCInterfaceDecl::PropertyMap SuperPropMap;
1843 CollectSuperClassPropertyImplementations(IDecl, SuperPropMap);
1844
1845 for (unsigned i = 0, e = PropertyOrder.size(); i != e; i++) {
1846 ObjCPropertyDecl *Prop = PropertyOrder[i];
1847 // Is there a matching property synthesize/dynamic?
1848 if (Prop->isInvalidDecl() ||
1849 Prop->isClassProperty() ||
1850 Prop->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1851 continue;
1852 // Property may have been synthesized by user.
1853 if (IMPDecl->FindPropertyImplDecl(
1854 Prop->getIdentifier(), Prop->getQueryKind()))
1855 continue;
1856 if (IMPDecl->getInstanceMethod(Prop->getGetterName())) {
1857 if (Prop->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_readonly)
1858 continue;
1859 if (IMPDecl->getInstanceMethod(Prop->getSetterName()))
1860 continue;
1861 }
1862 if (ObjCPropertyImplDecl *PID =
1863 IMPDecl->FindPropertyImplIvarDecl(Prop->getIdentifier())) {
1864 Diag(Prop->getLocation(), diag::warn_no_autosynthesis_shared_ivar_property)
1865 << Prop->getIdentifier();
1866 if (PID->getLocation().isValid())
1867 Diag(PID->getLocation(), diag::note_property_synthesize);
1868 continue;
1869 }
1870 ObjCPropertyDecl *PropInSuperClass =
1871 SuperPropMap[std::make_pair(Prop->getIdentifier(),
1872 Prop->isClassProperty())];
1873 if (ObjCProtocolDecl *Proto =
1874 dyn_cast<ObjCProtocolDecl>(Prop->getDeclContext())) {
1875 // We won't auto-synthesize properties declared in protocols.
1876 // Suppress the warning if class's superclass implements property's
1877 // getter and implements property's setter (if readwrite property).
1878 // Or, if property is going to be implemented in its super class.
1879 if (!SuperClassImplementsProperty(IDecl, Prop) && !PropInSuperClass) {
1880 Diag(IMPDecl->getLocation(),
1881 diag::warn_auto_synthesizing_protocol_property)
1882 << Prop << Proto;
1883 Diag(Prop->getLocation(), diag::note_property_declare);
1884 std::string FixIt =
1885 (Twine("@synthesize ") + Prop->getName() + ";\n\n").str();
1886 Diag(AtEnd, diag::note_add_synthesize_directive)
1887 << FixItHint::CreateInsertion(AtEnd, FixIt);
1888 }
1889 continue;
1890 }
1891 // If property to be implemented in the super class, ignore.
1892 if (PropInSuperClass) {
1893 if ((Prop->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_readwrite) &&
1894 (PropInSuperClass->getPropertyAttributes() &
1895 ObjCPropertyDecl::OBJC_PR_readonly) &&
1896 !IMPDecl->getInstanceMethod(Prop->getSetterName()) &&
1897 !IDecl->HasUserDeclaredSetterMethod(Prop)) {
1898 Diag(Prop->getLocation(), diag::warn_no_autosynthesis_property)
1899 << Prop->getIdentifier();
1900 Diag(PropInSuperClass->getLocation(), diag::note_property_declare);
1901 }
1902 else {
1903 Diag(Prop->getLocation(), diag::warn_autosynthesis_property_in_superclass)
1904 << Prop->getIdentifier();
1905 Diag(PropInSuperClass->getLocation(), diag::note_property_declare);
1906 Diag(IMPDecl->getLocation(), diag::note_while_in_implementation);
1907 }
1908 continue;
1909 }
1910 // We use invalid SourceLocations for the synthesized ivars since they
1911 // aren't really synthesized at a particular location; they just exist.
1912 // Saying that they are located at the @implementation isn't really going
1913 // to help users.
1914 ObjCPropertyImplDecl *PIDecl = dyn_cast_or_null<ObjCPropertyImplDecl>(
1915 ActOnPropertyImplDecl(S, SourceLocation(), SourceLocation(),
1916 true,
1917 /* property = */ Prop->getIdentifier(),
1918 /* ivar = */ Prop->getDefaultSynthIvarName(Context),
1919 Prop->getLocation(), Prop->getQueryKind()));
1920 if (PIDecl && !Prop->isUnavailable()) {
1921 Diag(Prop->getLocation(), diag::warn_missing_explicit_synthesis);
1922 Diag(IMPDecl->getLocation(), diag::note_while_in_implementation);
1923 }
1924 }
1925 }
1926
1927 void Sema::DefaultSynthesizeProperties(Scope *S, Decl *D,
1928 SourceLocation AtEnd) {
1929 if (!LangOpts.ObjCDefaultSynthProperties || LangOpts.ObjCRuntime.isFragile())
1930 return;
1931 ObjCImplementationDecl *IC=dyn_cast_or_null<ObjCImplementationDecl>(D);
1932 if (!IC)
1933 return;
1934 if (ObjCInterfaceDecl* IDecl = IC->getClassInterface())
1935 if (!IDecl->isObjCRequiresPropertyDefs())
1936 DefaultSynthesizeProperties(S, IC, IDecl, AtEnd);
1937 }
1938
1939 static void DiagnoseUnimplementedAccessor(
1940 Sema &S, ObjCInterfaceDecl *PrimaryClass, Selector Method,
1941 ObjCImplDecl *IMPDecl, ObjCContainerDecl *CDecl, ObjCCategoryDecl *C,
1942 ObjCPropertyDecl *Prop,
1943 llvm::SmallPtrSet<const ObjCMethodDecl *, 8> &SMap) {
1944 // Check to see if we have a corresponding selector in SMap and with the
1945 // right method type.
1946 auto I = std::find_if(SMap.begin(), SMap.end(),
1947 [&](const ObjCMethodDecl *x) {
1948 return x->getSelector() == Method &&
1949 x->isClassMethod() == Prop->isClassProperty();
1950 });
1951 // When reporting on missing property setter/getter implementation in
1952 // categories, do not report when they are declared in primary class,
1953 // class's protocol, or one of it super classes. This is because,
1954 // the class is going to implement them.
1955 if (I == SMap.end() &&
1956 (PrimaryClass == nullptr ||
1957 !PrimaryClass->lookupPropertyAccessor(Method, C,
1958 Prop->isClassProperty()))) {
1959 unsigned diag =
1960 isa<ObjCCategoryDecl>(CDecl)
1961 ? (Prop->isClassProperty()
1962 ? diag::warn_impl_required_in_category_for_class_property
1963 : diag::warn_setter_getter_impl_required_in_category)
1964 : (Prop->isClassProperty()
1965 ? diag::warn_impl_required_for_class_property
1966 : diag::warn_setter_getter_impl_required);
1967 S.Diag(IMPDecl->getLocation(), diag) << Prop->getDeclName() << Method;
1968 S.Diag(Prop->getLocation(), diag::note_property_declare);
1969 if (S.LangOpts.ObjCDefaultSynthProperties &&
1970 S.LangOpts.ObjCRuntime.isNonFragile())
1971 if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(CDecl))
1972 if (const ObjCInterfaceDecl *RID = ID->isObjCRequiresPropertyDefs())
1973 S.Diag(RID->getLocation(), diag::note_suppressed_class_declare);
1974 }
1975 }
1976
1977 void Sema::DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl,
1978 ObjCContainerDecl *CDecl,
1979 bool SynthesizeProperties) {
1980 ObjCContainerDecl::PropertyMap PropMap;
1981 ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(CDecl);
1982
1983 // Since we don't synthesize class properties, we should emit diagnose even
1984 // if SynthesizeProperties is true.
1985 ObjCContainerDecl::PropertyMap NoNeedToImplPropMap;
1986 // Gather properties which need not be implemented in this class
1987 // or category.
1988 if (!IDecl)
1989 if (ObjCCategoryDecl *C = dyn_cast<ObjCCategoryDecl>(CDecl)) {
1990 // For categories, no need to implement properties declared in
1991 // its primary class (and its super classes) if property is
1992 // declared in one of those containers.
1993 if ((IDecl = C->getClassInterface())) {
1994 ObjCInterfaceDecl::PropertyDeclOrder PO;
1995 IDecl->collectPropertiesToImplement(NoNeedToImplPropMap, PO);
1996 }
1997 }
1998 if (IDecl)
1999 CollectSuperClassPropertyImplementations(IDecl, NoNeedToImplPropMap);
2000
2001 // When SynthesizeProperties is true, we only check class properties.
2002 CollectImmediateProperties(CDecl, PropMap, NoNeedToImplPropMap,
2003 SynthesizeProperties/*CollectClassPropsOnly*/);
2004
2005 // Scan the @interface to see if any of the protocols it adopts
2006 // require an explicit implementation, via attribute
2007 // 'objc_protocol_requires_explicit_implementation'.
2008 if (IDecl) {
2009 std::unique_ptr<ObjCContainerDecl::PropertyMap> LazyMap;
2010
2011 for (auto *PDecl : IDecl->all_referenced_protocols()) {
2012 if (!PDecl->hasAttr<ObjCExplicitProtocolImplAttr>())
2013 continue;
2014 // Lazily construct a set of all the properties in the @interface
2015 // of the class, without looking at the superclass. We cannot
2016 // use the call to CollectImmediateProperties() above as that
2017 // utilizes information from the super class's properties as well
2018 // as scans the adopted protocols. This work only triggers for protocols
2019 // with the attribute, which is very rare, and only occurs when
2020 // analyzing the @implementation.
2021 if (!LazyMap) {
2022 ObjCContainerDecl::PropertyMap NoNeedToImplPropMap;
2023 LazyMap.reset(new ObjCContainerDecl::PropertyMap());
2024 CollectImmediateProperties(CDecl, *LazyMap, NoNeedToImplPropMap,
2025 /* CollectClassPropsOnly */ false,
2026 /* IncludeProtocols */ false);
2027 }
2028 // Add the properties of 'PDecl' to the list of properties that
2029 // need to be implemented.
2030 for (auto *PropDecl : PDecl->properties()) {
2031 if ((*LazyMap)[std::make_pair(PropDecl->getIdentifier(),
2032 PropDecl->isClassProperty())])
2033 continue;
2034 PropMap[std::make_pair(PropDecl->getIdentifier(),
2035 PropDecl->isClassProperty())] = PropDecl;
2036 }
2037 }
2038 }
2039
2040 if (PropMap.empty())
2041 return;
2042
2043 llvm::DenseSet<ObjCPropertyDecl *> PropImplMap;
2044 for (const auto *I : IMPDecl->property_impls())
2045 PropImplMap.insert(I->getPropertyDecl());
2046
2047 llvm::SmallPtrSet<const ObjCMethodDecl *, 8> InsMap;
2048 // Collect property accessors implemented in current implementation.
2049 for (const auto *I : IMPDecl->methods())
2050 InsMap.insert(I);
2051
2052 ObjCCategoryDecl *C = dyn_cast<ObjCCategoryDecl>(CDecl);
2053 ObjCInterfaceDecl *PrimaryClass = nullptr;
2054 if (C && !C->IsClassExtension())
2055 if ((PrimaryClass = C->getClassInterface()))
2056 // Report unimplemented properties in the category as well.
2057 if (ObjCImplDecl *IMP = PrimaryClass->getImplementation()) {
2058 // When reporting on missing setter/getters, do not report when
2059 // setter/getter is implemented in category's primary class
2060 // implementation.
2061 for (const auto *I : IMP->methods())
2062 InsMap.insert(I);
2063 }
2064
2065 for (ObjCContainerDecl::PropertyMap::iterator
2066 P = PropMap.begin(), E = PropMap.end(); P != E; ++P) {
2067 ObjCPropertyDecl *Prop = P->second;
2068 // Is there a matching property synthesize/dynamic?
2069 if (Prop->isInvalidDecl() ||
2070 Prop->getPropertyImplementation() == ObjCPropertyDecl::Optional ||
2071 PropImplMap.count(Prop) ||
2072 Prop->getAvailability() == AR_Unavailable)
2073 continue;
2074
2075 // Diagnose unimplemented getters and setters.
2076 DiagnoseUnimplementedAccessor(*this,
2077 PrimaryClass, Prop->getGetterName(), IMPDecl, CDecl, C, Prop, InsMap);
2078 if (!Prop->isReadOnly())
2079 DiagnoseUnimplementedAccessor(*this,
2080 PrimaryClass, Prop->getSetterName(),
2081 IMPDecl, CDecl, C, Prop, InsMap);
2082 }
2083 }
2084
2085 void Sema::diagnoseNullResettableSynthesizedSetters(const ObjCImplDecl *impDecl) {
2086 for (const auto *propertyImpl : impDecl->property_impls()) {
2087 const auto *property = propertyImpl->getPropertyDecl();
2088
2089 // Warn about null_resettable properties with synthesized setters,
2090 // because the setter won't properly handle nil.
2091 if (propertyImpl->getPropertyImplementation()
2092 == ObjCPropertyImplDecl::Synthesize &&
2093 (property->getPropertyAttributes() &
2094 ObjCPropertyDecl::OBJC_PR_null_resettable) &&
2095 property->getGetterMethodDecl() &&
2096 property->getSetterMethodDecl()) {
2097 auto *getterMethod = property->getGetterMethodDecl();
2098 auto *setterMethod = property->getSetterMethodDecl();
2099 if (!impDecl->getInstanceMethod(setterMethod->getSelector()) &&
2100 !impDecl->getInstanceMethod(getterMethod->getSelector())) {
2101 SourceLocation loc = propertyImpl->getLocation();
2102 if (loc.isInvalid())
2103 loc = impDecl->getBeginLoc();
2104
2105 Diag(loc, diag::warn_null_resettable_setter)
2106 << setterMethod->getSelector() << property->getDeclName();
2107 }
2108 }
2109 }
2110 }
2111
2112 void
2113 Sema::AtomicPropertySetterGetterRules (ObjCImplDecl* IMPDecl,
2114 ObjCInterfaceDecl* IDecl) {
2115 // Rules apply in non-GC mode only
2116 if (getLangOpts().getGC() != LangOptions::NonGC)
2117 return;
2118 ObjCContainerDecl::PropertyMap PM;
2119 for (auto *Prop : IDecl->properties())
2120 PM[std::make_pair(Prop->getIdentifier(), Prop->isClassProperty())] = Prop;
2121 for (const auto *Ext : IDecl->known_extensions())
2122 for (auto *Prop : Ext->properties())
2123 PM[std::make_pair(Prop->getIdentifier(), Prop->isClassProperty())] = Prop;
2124
2125 for (ObjCContainerDecl::PropertyMap::iterator I = PM.begin(), E = PM.end();
2126 I != E; ++I) {
2127 const ObjCPropertyDecl *Property = I->second;
2128 ObjCMethodDecl *GetterMethod = nullptr;
2129 ObjCMethodDecl *SetterMethod = nullptr;
2130 bool LookedUpGetterSetter = false;
2131
2132 unsigned Attributes = Property->getPropertyAttributes();
2133 unsigned AttributesAsWritten = Property->getPropertyAttributesAsWritten();
2134
2135 if (!(AttributesAsWritten & ObjCPropertyDecl::OBJC_PR_atomic) &&
2136 !(AttributesAsWritten & ObjCPropertyDecl::OBJC_PR_nonatomic)) {
2137 GetterMethod = Property->isClassProperty() ?
2138 IMPDecl->getClassMethod(Property->getGetterName()) :
2139 IMPDecl->getInstanceMethod(Property->getGetterName());
2140 SetterMethod = Property->isClassProperty() ?
2141 IMPDecl->getClassMethod(Property->getSetterName()) :
2142 IMPDecl->getInstanceMethod(Property->getSetterName());
2143 LookedUpGetterSetter = true;
2144 if (GetterMethod) {
2145 Diag(GetterMethod->getLocation(),
2146 diag::warn_default_atomic_custom_getter_setter)
2147 << Property->getIdentifier() << 0;
2148 Diag(Property->getLocation(), diag::note_property_declare);
2149 }
2150 if (SetterMethod) {
2151 Diag(SetterMethod->getLocation(),
2152 diag::warn_default_atomic_custom_getter_setter)
2153 << Property->getIdentifier() << 1;
2154 Diag(Property->getLocation(), diag::note_property_declare);
2155 }
2156 }
2157
2158 // We only care about readwrite atomic property.
2159 if ((Attributes & ObjCPropertyDecl::OBJC_PR_nonatomic) ||
2160 !(Attributes & ObjCPropertyDecl::OBJC_PR_readwrite))
2161 continue;
2162 if (const ObjCPropertyImplDecl *PIDecl = IMPDecl->FindPropertyImplDecl(
2163 Property->getIdentifier(), Property->getQueryKind())) {
2164 if (PIDecl->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic)
2165 continue;
2166 if (!LookedUpGetterSetter) {
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 }
2174 if ((GetterMethod && !SetterMethod) || (!GetterMethod && SetterMethod)) {
2175 SourceLocation MethodLoc =
2176 (GetterMethod ? GetterMethod->getLocation()
2177 : SetterMethod->getLocation());
2178 Diag(MethodLoc, diag::warn_atomic_property_rule)
2179 << Property->getIdentifier() << (GetterMethod != nullptr)
2180 << (SetterMethod != nullptr);
2181 // fixit stuff.
2182 if (Property->getLParenLoc().isValid() &&
2183 !(AttributesAsWritten & ObjCPropertyDecl::OBJC_PR_atomic)) {
2184 // @property () ... case.
2185 SourceLocation AfterLParen =
2186 getLocForEndOfToken(Property->getLParenLoc());
2187 StringRef NonatomicStr = AttributesAsWritten? "nonatomic, "
2188 : "nonatomic";
2189 Diag(Property->getLocation(),
2190 diag::note_atomic_property_fixup_suggest)
2191 << FixItHint::CreateInsertion(AfterLParen, NonatomicStr);
2192 } else if (Property->getLParenLoc().isInvalid()) {
2193 //@property id etc.
2194 SourceLocation startLoc =
2195 Property->getTypeSourceInfo()->getTypeLoc().getBeginLoc();
2196 Diag(Property->getLocation(),
2197 diag::note_atomic_property_fixup_suggest)
2198 << FixItHint::CreateInsertion(startLoc, "(nonatomic) ");
2199 }
2200 else
2201 Diag(MethodLoc, diag::note_atomic_property_fixup_suggest);
2202 Diag(Property->getLocation(), diag::note_property_declare);
2203 }
2204 }
2205 }
2206 }
2207
2208 void Sema::DiagnoseOwningPropertyGetterSynthesis(const ObjCImplementationDecl *D) {
2209 if (getLangOpts().getGC() == LangOptions::GCOnly)
2210 return;
2211
2212 for (const auto *PID : D->property_impls()) {
2213 const ObjCPropertyDecl *PD = PID->getPropertyDecl();
2214 if (PD && !PD->hasAttr<NSReturnsNotRetainedAttr>() &&
2215 !PD->isClassProperty() &&
2216 !D->getInstanceMethod(PD->getGetterName())) {
2217 ObjCMethodDecl *method = PD->getGetterMethodDecl();
2218 if (!method)
2219 continue;
2220 ObjCMethodFamily family = method->getMethodFamily();
2221 if (family == OMF_alloc || family == OMF_copy ||
2222 family == OMF_mutableCopy || family == OMF_new) {
2223 if (getLangOpts().ObjCAutoRefCount)
2224 Diag(PD->getLocation(), diag::err_cocoa_naming_owned_rule);
2225 else
2226 Diag(PD->getLocation(), diag::warn_cocoa_naming_owned_rule);
2227
2228 // Look for a getter explicitly declared alongside the property.
2229 // If we find one, use its location for the note.
2230 SourceLocation noteLoc = PD->getLocation();
2231 SourceLocation fixItLoc;
2232 for (auto *getterRedecl : method->redecls()) {
2233 if (getterRedecl->isImplicit())
2234 continue;
2235 if (getterRedecl->getDeclContext() != PD->getDeclContext())
2236 continue;
2237 noteLoc = getterRedecl->getLocation();
2238 fixItLoc = getterRedecl->getEndLoc();
2239 }
2240
2241 Preprocessor &PP = getPreprocessor();
2242 TokenValue tokens[] = {
2243 tok::kw___attribute, tok::l_paren, tok::l_paren,
2244 PP.getIdentifierInfo("objc_method_family"), tok::l_paren,
2245 PP.getIdentifierInfo("none"), tok::r_paren,
2246 tok::r_paren, tok::r_paren
2247 };
2248 StringRef spelling = "__attribute__((objc_method_family(none)))";
2249 StringRef macroName = PP.getLastMacroWithSpelling(noteLoc, tokens);
2250 if (!macroName.empty())
2251 spelling = macroName;
2252
2253 auto noteDiag = Diag(noteLoc, diag::note_cocoa_naming_declare_family)
2254 << method->getDeclName() << spelling;
2255 if (fixItLoc.isValid()) {
2256 SmallString<64> fixItText(" ");
2257 fixItText += spelling;
2258 noteDiag << FixItHint::CreateInsertion(fixItLoc, fixItText);
2259 }
2260 }
2261 }
2262 }
2263 }
2264
2265 void Sema::DiagnoseMissingDesignatedInitOverrides(
2266 const ObjCImplementationDecl *ImplD,
2267 const ObjCInterfaceDecl *IFD) {
2268 assert(IFD->hasDesignatedInitializers());
2269 const ObjCInterfaceDecl *SuperD = IFD->getSuperClass();
2270 if (!SuperD)
2271 return;
2272
2273 SelectorSet InitSelSet;
2274 for (const auto *I : ImplD->instance_methods())
2275 if (I->getMethodFamily() == OMF_init)
2276 InitSelSet.insert(I->getSelector());
2277
2278 SmallVector<const ObjCMethodDecl *, 8> DesignatedInits;
2279 SuperD->getDesignatedInitializers(DesignatedInits);
2280 for (SmallVector<const ObjCMethodDecl *, 8>::iterator
2281 I = DesignatedInits.begin(), E = DesignatedInits.end(); I != E; ++I) {
2282 const ObjCMethodDecl *MD = *I;
2283 if (!InitSelSet.count(MD->getSelector())) {
2284 bool Ignore = false;
2285 if (auto *IMD = IFD->getInstanceMethod(MD->getSelector())) {
2286 Ignore = IMD->isUnavailable();
2287 }
2288 if (!Ignore) {
2289 Diag(ImplD->getLocation(),
2290 diag::warn_objc_implementation_missing_designated_init_override)
2291 << MD->getSelector();
2292 Diag(MD->getLocation(), diag::note_objc_designated_init_marked_here);
2293 }
2294 }
2295 }
2296 }
2297
2298 /// AddPropertyAttrs - Propagates attributes from a property to the
2299 /// implicitly-declared getter or setter for that property.
2300 static void AddPropertyAttrs(Sema &S, ObjCMethodDecl *PropertyMethod,
2301 ObjCPropertyDecl *Property) {
2302 // Should we just clone all attributes over?
2303 for (const auto *A : Property->attrs()) {
2304 if (isa<DeprecatedAttr>(A) ||
2305 isa<UnavailableAttr>(A) ||
2306 isa<AvailabilityAttr>(A))
2307 PropertyMethod->addAttr(A->clone(S.Context));
2308 }
2309 }
2310
2311 /// ProcessPropertyDecl - Make sure that any user-defined setter/getter methods
2312 /// have the property type and issue diagnostics if they don't.
2313 /// Also synthesize a getter/setter method if none exist (and update the
2314 /// appropriate lookup tables.
2315 void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property) {
2316 ObjCMethodDecl *GetterMethod, *SetterMethod;
2317 ObjCContainerDecl *CD = cast<ObjCContainerDecl>(property->getDeclContext());
2318 if (CD->isInvalidDecl())
2319 return;
2320
2321 bool IsClassProperty = property->isClassProperty();
2322 GetterMethod = IsClassProperty ?
2323 CD->getClassMethod(property->getGetterName()) :
2324 CD->getInstanceMethod(property->getGetterName());
2325
2326 // if setter or getter is not found in class extension, it might be
2327 // in the primary class.
2328 if (!GetterMethod)
2329 if (const ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(CD))
2330 if (CatDecl->IsClassExtension())
2331 GetterMethod = IsClassProperty ? CatDecl->getClassInterface()->
2332 getClassMethod(property->getGetterName()) :
2333 CatDecl->getClassInterface()->
2334 getInstanceMethod(property->getGetterName());
2335
2336 SetterMethod = IsClassProperty ?
2337 CD->getClassMethod(property->getSetterName()) :
2338 CD->getInstanceMethod(property->getSetterName());
2339 if (!SetterMethod)
2340 if (const ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(CD))
2341 if (CatDecl->IsClassExtension())
2342 SetterMethod = IsClassProperty ? CatDecl->getClassInterface()->
2343 getClassMethod(property->getSetterName()) :
2344 CatDecl->getClassInterface()->
2345 getInstanceMethod(property->getSetterName());
2346 DiagnosePropertyAccessorMismatch(property, GetterMethod,
2347 property->getLocation());
2348
2349 if (!property->isReadOnly() && SetterMethod) {
2350 if (Context.getCanonicalType(SetterMethod->getReturnType()) !=
2351 Context.VoidTy)
2352 Diag(SetterMethod->getLocation(), diag::err_setter_type_void);
2353 if (SetterMethod->param_size() != 1 ||
2354 !Context.hasSameUnqualifiedType(
2355 (*SetterMethod->param_begin())->getType().getNonReferenceType(),
2356 property->getType().getNonReferenceType())) {
2357 Diag(property->getLocation(),
2358 diag::warn_accessor_property_type_mismatch)
2359 << property->getDeclName()
2360 << SetterMethod->getSelector();
2361 Diag(SetterMethod->getLocation(), diag::note_declared_at);
2362 }
2363 }
2364
2365 // Synthesize getter/setter methods if none exist.
2366 // Find the default getter and if one not found, add one.
2367 // FIXME: The synthesized property we set here is misleading. We almost always
2368 // synthesize these methods unless the user explicitly provided prototypes
2369 // (which is odd, but allowed). Sema should be typechecking that the
2370 // declarations jive in that situation (which it is not currently).
2371 if (!GetterMethod) {
2372 // No instance/class method of same name as property getter name was found.
2373 // Declare a getter method and add it to the list of methods
2374 // for this class.
2375 SourceLocation Loc = property->getLocation();
2376
2377 // The getter returns the declared property type with all qualifiers
2378 // removed.
2379 QualType resultTy = property->getType().getAtomicUnqualifiedType();
2380
2381 // If the property is null_resettable, the getter returns nonnull.
2382 if (property->getPropertyAttributes() &
2383 ObjCPropertyDecl::OBJC_PR_null_resettable) {
2384 QualType modifiedTy = resultTy;
2385 if (auto nullability = AttributedType::stripOuterNullability(modifiedTy)) {
2386 if (*nullability == NullabilityKind::Unspecified)
2387 resultTy = Context.getAttributedType(attr::TypeNonNull,
2388 modifiedTy, modifiedTy);
2389 }
2390 }
2391
2392 GetterMethod = ObjCMethodDecl::Create(Context, Loc, Loc,
2393 property->getGetterName(),
2394 resultTy, nullptr, CD,
2395 !IsClassProperty, /*isVariadic=*/false,
2396 /*isPropertyAccessor=*/true,
2397 /*isImplicitlyDeclared=*/true, /*isDefined=*/false,
2398 (property->getPropertyImplementation() ==
2399 ObjCPropertyDecl::Optional) ?
2400 ObjCMethodDecl::Optional :
2401 ObjCMethodDecl::Required);
2402 CD->addDecl(GetterMethod);
2403
2404 AddPropertyAttrs(*this, GetterMethod, property);
2405
2406 if (property->hasAttr<NSReturnsNotRetainedAttr>())
2407 GetterMethod->addAttr(NSReturnsNotRetainedAttr::CreateImplicit(Context,
2408 Loc));
2409
2410 if (property->hasAttr<ObjCReturnsInnerPointerAttr>())
2411 GetterMethod->addAttr(
2412 ObjCReturnsInnerPointerAttr::CreateImplicit(Context, Loc));
2413
2414 if (const SectionAttr *SA = property->getAttr<SectionAttr>())
2415 GetterMethod->addAttr(
2416 SectionAttr::CreateImplicit(Context, SectionAttr::GNU_section,
2417 SA->getName(), Loc));
2418
2419 if (getLangOpts().ObjCAutoRefCount)
2420 CheckARCMethodDecl(GetterMethod);
2421 } else
2422 // A user declared getter will be synthesize when @synthesize of
2423 // the property with the same name is seen in the @implementation
2424 GetterMethod->setPropertyAccessor(true);
2425 property->setGetterMethodDecl(GetterMethod);
2426
2427 // Skip setter if property is read-only.
2428 if (!property->isReadOnly()) {
2429 // Find the default setter and if one not found, add one.
2430 if (!SetterMethod) {
2431 // No instance/class method of same name as property setter name was
2432 // found.
2433 // Declare a setter method and add it to the list of methods
2434 // for this class.
2435 SourceLocation Loc = property->getLocation();
2436
2437 SetterMethod =
2438 ObjCMethodDecl::Create(Context, Loc, Loc,
2439 property->getSetterName(), Context.VoidTy,
2440 nullptr, CD, !IsClassProperty,
2441 /*isVariadic=*/false,
2442 /*isPropertyAccessor=*/true,
2443 /*isImplicitlyDeclared=*/true,
2444 /*isDefined=*/false,
2445 (property->getPropertyImplementation() ==
2446 ObjCPropertyDecl::Optional) ?
2447 ObjCMethodDecl::Optional :
2448 ObjCMethodDecl::Required);
2449
2450 // Remove all qualifiers from the setter's parameter type.
2451 QualType paramTy =
2452 property->getType().getUnqualifiedType().getAtomicUnqualifiedType();
2453
2454 // If the property is null_resettable, the setter accepts a
2455 // nullable value.
2456 if (property->getPropertyAttributes() &
2457 ObjCPropertyDecl::OBJC_PR_null_resettable) {
2458 QualType modifiedTy = paramTy;
2459 if (auto nullability = AttributedType::stripOuterNullability(modifiedTy)){
2460 if (*nullability == NullabilityKind::Unspecified)
2461 paramTy = Context.getAttributedType(attr::TypeNullable,
2462 modifiedTy, modifiedTy);
2463 }
2464 }
2465
2466 // Invent the arguments for the setter. We don't bother making a
2467 // nice name for the argument.
2468 ParmVarDecl *Argument = ParmVarDecl::Create(Context, SetterMethod,
2469 Loc, Loc,
2470 property->getIdentifier(),
2471 paramTy,
2472 /*TInfo=*/nullptr,
2473 SC_None,
2474 nullptr);
2475 SetterMethod->setMethodParams(Context, Argument, None);
2476
2477 AddPropertyAttrs(*this, SetterMethod, property);
2478
2479 CD->addDecl(SetterMethod);
2480 if (const SectionAttr *SA = property->getAttr<SectionAttr>())
2481 SetterMethod->addAttr(
2482 SectionAttr::CreateImplicit(Context, SectionAttr::GNU_section,
2483 SA->getName(), Loc));
2484 // It's possible for the user to have set a very odd custom
2485 // setter selector that causes it to have a method family.
2486 if (getLangOpts().ObjCAutoRefCount)
2487 CheckARCMethodDecl(SetterMethod);
2488 } else
2489 // A user declared setter will be synthesize when @synthesize of
2490 // the property with the same name is seen in the @implementation
2491 SetterMethod->setPropertyAccessor(true);
2492 property->setSetterMethodDecl(SetterMethod);
2493 }
2494 // Add any synthesized methods to the global pool. This allows us to
2495 // handle the following, which is supported by GCC (and part of the design).
2496 //
2497 // @interface Foo
2498 // @property double bar;
2499 // @end
2500 //
2501 // void thisIsUnfortunate() {
2502 // id foo;
2503 // double bar = [foo bar];
2504 // }
2505 //
2506 if (!IsClassProperty) {
2507 if (GetterMethod)
2508 AddInstanceMethodToGlobalPool(GetterMethod);
2509 if (SetterMethod)
2510 AddInstanceMethodToGlobalPool(SetterMethod);
2511 } else {
2512 if (GetterMethod)
2513 AddFactoryMethodToGlobalPool(GetterMethod);
2514 if (SetterMethod)
2515 AddFactoryMethodToGlobalPool(SetterMethod);
2516 }
2517
2518 ObjCInterfaceDecl *CurrentClass = dyn_cast<ObjCInterfaceDecl>(CD);
2519 if (!CurrentClass) {
2520 if (ObjCCategoryDecl *Cat = dyn_cast<ObjCCategoryDecl>(CD))
2521 CurrentClass = Cat->getClassInterface();
2522 else if (ObjCImplDecl *Impl = dyn_cast<ObjCImplDecl>(CD))
2523 CurrentClass = Impl->getClassInterface();
2524 }
2525 if (GetterMethod)
2526 CheckObjCMethodOverrides(GetterMethod, CurrentClass, Sema::RTC_Unknown);
2527 if (SetterMethod)
2528 CheckObjCMethodOverrides(SetterMethod, CurrentClass, Sema::RTC_Unknown);
2529 }
2530
2531 void Sema::CheckObjCPropertyAttributes(Decl *PDecl,
2532 SourceLocation Loc,
2533 unsigned &Attributes,
2534 bool propertyInPrimaryClass) {
2535 // FIXME: Improve the reported location.
2536 if (!PDecl || PDecl->isInvalidDecl())
2537 return;
2538
2539 if ((Attributes & ObjCDeclSpec::DQ_PR_readonly) &&
2540 (Attributes & ObjCDeclSpec::DQ_PR_readwrite))
2541 Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
2542 << "readonly" << "readwrite";
2543
2544 ObjCPropertyDecl *PropertyDecl = cast<ObjCPropertyDecl>(PDecl);
2545 QualType PropertyTy = PropertyDecl->getType();
2546
2547 // Check for copy or retain on non-object types.
2548 if ((Attributes & (ObjCDeclSpec::DQ_PR_weak | ObjCDeclSpec::DQ_PR_copy |
2549 ObjCDeclSpec::DQ_PR_retain | ObjCDeclSpec::DQ_PR_strong)) &&
2550 !PropertyTy->isObjCRetainableType() &&
2551 !PropertyDecl->hasAttr<ObjCNSObjectAttr>()) {
2552 Diag(Loc, diag::err_objc_property_requires_object)
2553 << (Attributes & ObjCDeclSpec::DQ_PR_weak ? "weak" :
2554 Attributes & ObjCDeclSpec::DQ_PR_copy ? "copy" : "retain (or strong)");
2555 Attributes &= ~(ObjCDeclSpec::DQ_PR_weak | ObjCDeclSpec::DQ_PR_copy |
2556 ObjCDeclSpec::DQ_PR_retain | ObjCDeclSpec::DQ_PR_strong);
2557 PropertyDecl->setInvalidDecl();
2558 }
2559
2560 // Check for assign on object types.
2561 if ((Attributes & ObjCDeclSpec::DQ_PR_assign) &&
2562 !(Attributes & ObjCDeclSpec::DQ_PR_unsafe_unretained) &&
2563 PropertyTy->isObjCRetainableType() &&
2564 !PropertyTy->isObjCARCImplicitlyUnretainedType()) {
2565 Diag(Loc, diag::warn_objc_property_assign_on_object);
2566 }
2567
2568 // Check for more than one of { assign, copy, retain }.
2569 if (Attributes & ObjCDeclSpec::DQ_PR_assign) {
2570 if (Attributes & ObjCDeclSpec::DQ_PR_copy) {
2571 Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
2572 << "assign" << "copy";
2573 Attributes &= ~ObjCDeclSpec::DQ_PR_copy;
2574 }
2575 if (Attributes & ObjCDeclSpec::DQ_PR_retain) {
2576 Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
2577 << "assign" << "retain";
2578 Attributes &= ~ObjCDeclSpec::DQ_PR_retain;
2579 }
2580 if (Attributes & ObjCDeclSpec::DQ_PR_strong) {
2581 Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
2582 << "assign" << "strong";
2583 Attributes &= ~ObjCDeclSpec::DQ_PR_strong;
2584 }
2585 if (getLangOpts().ObjCAutoRefCount &&
2586 (Attributes & ObjCDeclSpec::DQ_PR_weak)) {
2587 Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
2588 << "assign" << "weak";
2589 Attributes &= ~ObjCDeclSpec::DQ_PR_weak;
2590 }
2591 if (PropertyDecl->hasAttr<IBOutletCollectionAttr>())
2592 Diag(Loc, diag::warn_iboutletcollection_property_assign);
2593 } else if (Attributes & ObjCDeclSpec::DQ_PR_unsafe_unretained) {
2594 if (Attributes & ObjCDeclSpec::DQ_PR_copy) {
2595 Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
2596 << "unsafe_unretained" << "copy";
2597 Attributes &= ~ObjCDeclSpec::DQ_PR_copy;
2598 }
2599 if (Attributes & ObjCDeclSpec::DQ_PR_retain) {
2600 Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
2601 << "unsafe_unretained" << "retain";
2602 Attributes &= ~ObjCDeclSpec::DQ_PR_retain;
2603 }
2604 if (Attributes & ObjCDeclSpec::DQ_PR_strong) {
2605 Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
2606 << "unsafe_unretained" << "strong";
2607 Attributes &= ~ObjCDeclSpec::DQ_PR_strong;
2608 }
2609 if (getLangOpts().ObjCAutoRefCount &&
2610 (Attributes & ObjCDeclSpec::DQ_PR_weak)) {
2611 Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
2612 << "unsafe_unretained" << "weak";
2613 Attributes &= ~ObjCDeclSpec::DQ_PR_weak;
2614 }
2615 } else if (Attributes & ObjCDeclSpec::DQ_PR_copy) {
2616 if (Attributes & ObjCDeclSpec::DQ_PR_retain) {
2617 Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
2618 << "copy" << "retain";
2619 Attributes &= ~ObjCDeclSpec::DQ_PR_retain;
2620 }
2621 if (Attributes & ObjCDeclSpec::DQ_PR_strong) {
2622 Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
2623 << "copy" << "strong";
2624 Attributes &= ~ObjCDeclSpec::DQ_PR_strong;
2625 }
2626 if (Attributes & ObjCDeclSpec::DQ_PR_weak) {
2627 Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
2628 << "copy" << "weak";
2629 Attributes &= ~ObjCDeclSpec::DQ_PR_weak;
2630 }
2631 }
2632 else if ((Attributes & ObjCDeclSpec::DQ_PR_retain) &&
2633 (Attributes & ObjCDeclSpec::DQ_PR_weak)) {
2634 Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
2635 << "retain" << "weak";
2636 Attributes &= ~ObjCDeclSpec::DQ_PR_retain;
2637 }
2638 else if ((Attributes & ObjCDeclSpec::DQ_PR_strong) &&
2639 (Attributes & ObjCDeclSpec::DQ_PR_weak)) {
2640 Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
2641 << "strong" << "weak";
2642 Attributes &= ~ObjCDeclSpec::DQ_PR_weak;
2643 }
2644
2645 if (Attributes & ObjCDeclSpec::DQ_PR_weak) {
2646 // 'weak' and 'nonnull' are mutually exclusive.
2647 if (auto nullability = PropertyTy->getNullability(Context)) {
2648 if (*nullability == NullabilityKind::NonNull)
2649 Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
2650 << "nonnull" << "weak";
2651 }
2652 }
2653
2654 if ((Attributes & ObjCDeclSpec::DQ_PR_atomic) &&
2655 (Attributes & ObjCDeclSpec::DQ_PR_nonatomic)) {
2656 Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
2657 << "atomic" << "nonatomic";
2658 Attributes &= ~ObjCDeclSpec::DQ_PR_atomic;
2659 }
2660
2661 // Warn if user supplied no assignment attribute, property is
2662 // readwrite, and this is an object type.
2663 if (!getOwnershipRule(Attributes) && PropertyTy->isObjCRetainableType()) {
2664 if (Attributes & ObjCDeclSpec::DQ_PR_readonly) {
2665 // do nothing
2666 } else if (getLangOpts().ObjCAutoRefCount) {
2667 // With arc, @property definitions should default to strong when
2668 // not specified.
2669 PropertyDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_strong);
2670 } else if (PropertyTy->isObjCObjectPointerType()) {
2671 bool isAnyClassTy =
2672 (PropertyTy->isObjCClassType() ||
2673 PropertyTy->isObjCQualifiedClassType());
2674 // In non-gc, non-arc mode, 'Class' is treated as a 'void *' no need to
2675 // issue any warning.
2676 if (isAnyClassTy && getLangOpts().getGC() == LangOptions::NonGC)
2677 ;
2678 else if (propertyInPrimaryClass) {
2679 // Don't issue warning on property with no life time in class
2680 // extension as it is inherited from property in primary class.
2681 // Skip this warning in gc-only mode.
2682 if (getLangOpts().getGC() != LangOptions::GCOnly)
2683 Diag(Loc, diag::warn_objc_property_no_assignment_attribute);
2684
2685 // If non-gc code warn that this is likely inappropriate.
2686 if (getLangOpts().getGC() == LangOptions::NonGC)
2687 Diag(Loc, diag::warn_objc_property_default_assign_on_object);
2688 }
2689 }
2690
2691 // FIXME: Implement warning dependent on NSCopying being
2692 // implemented. See also:
2693 // <rdar://5168496&4855821&5607453&5096644&4947311&5698469&4947014&5168496>
2694 // (please trim this list while you are at it).
2695 }
2696
2697 if (!(Attributes & ObjCDeclSpec::DQ_PR_copy)
2698 &&!(Attributes & ObjCDeclSpec::DQ_PR_readonly)
2699 && getLangOpts().getGC() == LangOptions::GCOnly
2700 && PropertyTy->isBlockPointerType())
2701 Diag(Loc, diag::warn_objc_property_copy_missing_on_block);
2702 else if ((Attributes & ObjCDeclSpec::DQ_PR_retain) &&
2703 !(Attributes & ObjCDeclSpec::DQ_PR_readonly) &&
2704 !(Attributes & ObjCDeclSpec::DQ_PR_strong) &&
2705 PropertyTy->isBlockPointerType())
2706 Diag(Loc, diag::warn_objc_property_retain_of_block);
2707
2708 if ((Attributes & ObjCDeclSpec::DQ_PR_readonly) &&
2709 (Attributes & ObjCDeclSpec::DQ_PR_setter))
2710 Diag(Loc, diag::warn_objc_readonly_property_has_setter);
2711 }
clang::CXXOperatorCallExpr
A call to an overloaded operator written using operator syntax.
Definition: ExprCXX.h:78
clang::SourceManager::getLocForStartOfFile
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file. ...
Definition: SourceManager.h:1067
clang::AR_Unavailable
Definition: DeclBase.h:77
clang::Builtin::ID
ID
Definition: Builtins.h:49
clang::ObjCPropertyDecl::getQueryKind
ObjCPropertyQueryKind getQueryKind() const
Definition: DeclObjC.h:881
clang::ast_matchers::callExpr
const internal::VariadicDynCastAllOfMatcher< Stmt, CallExpr > callExpr
Matches call expressions.
Definition: ASTMatchersInternal.cpp:622
clang::Sema::RequireNonAbstractType
bool RequireNonAbstractType(SourceLocation Loc, QualType T, TypeDiagnoser &Diagnoser)
Definition: SemaDeclCXX.cpp:5296
clang::FunctionDecl
Represents a function declaration or definition.
Definition: Decl.h:1738
clang::Lexer
Lexer - This provides a simple interface that turns a text buffer into a stream of tokens...
Definition: Lexer.h:77
clang::SourceLocation::getLocWithOffset
SourceLocation getLocWithOffset(int Offset) const
Return a source location with the specified offset from this SourceLocation.
Definition: SourceLocation.h:134
clang::ObjCInterfaceDecl::protocols
protocol_range protocols() const
Definition: DeclObjC.h:1366
clang::Selector
Smart pointer class that efficiently represents Objective-C method names.
Definition: IdentifierTable.h:673
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:638
clang::ObjCCategoryDecl::getClassInterface
ObjCInterfaceDecl * getClassInterface()
Definition: DeclObjC.h:2325
clang::ObjCInterfaceDecl::all_referenced_protocols
all_protocol_range all_referenced_protocols() const
Definition: DeclObjC.h:1424
clang::ObjCMethodDecl::getClassInterface
ObjCInterfaceDecl * getClassInterface()
Definition: DeclObjC.cpp:1144
clang::Sema::IvarBacksCurrentMethodAccessor
bool IvarBacksCurrentMethodAccessor(ObjCInterfaceDecl *IFace, ObjCMethodDecl *Method, ObjCIvarDecl *IV)
IvarBacksCurrentMethodAccessor - This routine returns &#39;true&#39; if &#39;IV&#39; is an ivar synthesized for &#39;Meth...
Definition: SemaObjCProperty.cpp:1783
clang::Preprocessor::getIdentifierInfo
IdentifierInfo * getIdentifierInfo(StringRef Name) const
Return information about the specified preprocessor identifier token.
Definition: Preprocessor.h:1066
clang::Sema::isObjCPointerConversion
bool isObjCPointerConversion(QualType FromType, QualType ToType, QualType &ConvertedType, bool &IncompatibleObjC)
isObjCPointerConversion - Determines whether this is an Objective-C pointer conversion.
Definition: SemaOverload.cpp:2426
clang::Type::isArithmeticType
bool isArithmeticType() const
Definition: Type.cpp:1952
clang::Sema::ActOnProperty
Decl * ActOnProperty(Scope *S, SourceLocation AtLoc, SourceLocation LParenLoc, FieldDeclarator &FD, ObjCDeclSpec &ODS, Selector GetterSel, Selector SetterSel, tok::ObjCKeywordKind MethodImplKind, DeclContext *lexicalDC=nullptr)
Definition: SemaObjCProperty.cpp:178
SourceManager.h
Defines the SourceManager interface.
clang::Sema::ActOnDocumentableDecl
void ActOnDocumentableDecl(Decl *D)
Should be called on all declarations that might have attached documentation comments.
Definition: SemaDecl.cpp:12298
clang::ObjCPropertyImplDecl::Dynamic
Definition: DeclObjC.h:2763
clang::Qualifiers::setObjCLifetime
void setObjCLifetime(ObjCLifetime type)
Definition: Type.h:329
CollectSuperClassPropertyImplementations
static void CollectSuperClassPropertyImplementations(ObjCInterfaceDecl *CDecl, ObjCInterfaceDecl::PropertyMap &PropMap)
CollectSuperClassPropertyImplementations - This routine collects list of properties to be implemented...
Definition: SemaObjCProperty.cpp:1768
clang::Type::isRecordType
bool isRecordType() const
Definition: Type.h:6369
clang::ObjCContainerDecl::PropertyDeclOrder
llvm::SmallVector< ObjCPropertyDecl *, 8 > PropertyDeclOrder
Definition: DeclObjC.h:1107
clang::ASTContext::getQualifiedType
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
Definition: ASTContext.h:1933
clang::Sema::Diag
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Definition: Sema.h:1308
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:87
clang::Sema::DiagnoseMissingDesignatedInitOverrides
void DiagnoseMissingDesignatedInitOverrides(const ObjCImplementationDecl *ImplD, const ObjCInterfaceDecl *IFD)
Definition: SemaObjCProperty.cpp:2265
clang::Sema::CheckObjCPropertyAttributes
void CheckObjCPropertyAttributes(Decl *PropertyPtrTy, SourceLocation Loc, unsigned &Attributes, bool propertyInPrimaryClass)
Ensure attributes are consistent with type.
Definition: SemaObjCProperty.cpp:2531
clang::Decl::getBeginLoc
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclBase.h:410
clang::ObjCDeclSpec
Captures information about "declaration specifiers" specific to Objective-C.
Definition: DeclSpec.h:789
llvm::DenseSet
Definition: Sema.h:66
P
StringRef P
Definition: ASTMatchersInternal.cpp:439
clang::ObjCDeclSpec::DQ_PR_class
Definition: DeclSpec.h:826
clang::QualType::getNonReferenceType
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
Definition: Type.h:6245
clang::ObjCPropertyDecl::Create
static ObjCPropertyDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, SourceLocation AtLocation, SourceLocation LParenLocation, QualType T, TypeSourceInfo *TSI, PropertyControl propControl=None)
Definition: DeclObjC.cpp:2219
clang::Sema::AddFactoryMethodToGlobalPool
void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false)
AddFactoryMethodToGlobalPool - Same as above, but for factory methods.
Definition: Sema.h:3626
clang::CanQual::getUnqualifiedType
CanQual< T > getUnqualifiedType() const
Retrieve the unqualified form of this type.
Definition: CanonicalType.h:619
clang::Preprocessor::getLastMacroWithSpelling
StringRef getLastMacroWithSpelling(SourceLocation Loc, ArrayRef< TokenValue > Tokens) const
Return the name of the macro defined before Loc that has spelling Tokens.
Definition: Preprocessor.cpp:345
clang::Sema::getLocForEndOfToken
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Calls Lexer::getLocForEndOfToken()
Definition: Sema.cpp:46
clang::ObjCPropertyDecl::setPropertyImplementation
void setPropertyImplementation(PropertyControl pc)
Definition: DeclObjC.h:929
DeclObjC.h
clang::TypeSourceInfo
A container of type source information.
Definition: Decl.h:87
clang::Sema::ProcessPropertyDecl
void ProcessPropertyDecl(ObjCPropertyDecl *property)
Process the specified property declaration and create decls for the setters and getters as needed...
Definition: SemaObjCProperty.cpp:2315
clang::ObjCMethodDecl::setPropertyAccessor
void setPropertyAccessor(bool isAccessor)
Definition: DeclObjC.h:436
clang::TypeLoc::getEndLoc
SourceLocation getEndLoc() const
Get the end source location.
Definition: TypeLoc.cpp:227
areIncompatiblePropertyAttributes
static bool areIncompatiblePropertyAttributes(unsigned Attr1, unsigned Attr2, unsigned Kinds)
Definition: SemaObjCProperty.cpp:823
clang::Sema::ActOnPropertyImplDecl
Decl * ActOnPropertyImplDecl(Scope *S, SourceLocation AtLoc, SourceLocation PropertyLoc, bool ImplKind, IdentifierInfo *PropertyId, IdentifierInfo *PropertyIvar, SourceLocation PropertyIvarLoc, ObjCPropertyQueryKind QueryKind)
ActOnPropertyImplDecl - This routine performs semantic checks and builds the AST node for a property ...
Definition: SemaObjCProperty.cpp:1045
clang::SourceManager::getBufferData
StringRef getBufferData(FileID FID, bool *Invalid=nullptr) const
Return a StringRef to the source buffer data for the specified FileID.
Definition: SourceManager.cpp:670
clang::Sema::SynthesizedFunctionScope
RAII object to handle the state changes required to synthesize a function body.
Definition: Sema.h:762
clang::SC_None
Definition: Specifiers.h:208
clang::ObjCPropertyDecl::PropertyAttributeKind
PropertyAttributeKind
Definition: DeclObjC.h:733
clang::Type::getAs
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:6748
clang::ObjCDeclSpec::DQ_PR_nonatomic
Definition: DeclSpec.h:818
getOwnershipRule
static unsigned getOwnershipRule(unsigned attr)
Definition: SemaObjCProperty.cpp:164
clang::ObjCMethodDecl
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:139
clang::Sema::HandlePropertyInClassExtension
ObjCPropertyDecl * HandlePropertyInClassExtension(Scope *S, SourceLocation AtLoc, SourceLocation LParenLoc, FieldDeclarator &FD, Selector GetterSel, SourceLocation GetterNameLoc, Selector SetterSel, SourceLocation SetterNameLoc, const bool isReadWrite, unsigned &Attributes, const unsigned AttributesAsWritten, QualType T, TypeSourceInfo *TSI, tok::ObjCKeywordKind MethodImplKind)
Called by ActOnProperty to handle @property declarations in class extensions.
Definition: SemaObjCProperty.cpp:413
clang::ObjCInterfaceDecl::ClassImplementsProtocol
bool ClassImplementsProtocol(ObjCProtocolDecl *lProto, bool lookupCategory, bool RHSIsQualifiedID=false)
ClassImplementsProtocol - Checks that &#39;lProto&#39; protocol has been implemented in IDecl class...
Definition: DeclObjC.cpp:1703
clang::ObjCMethodDecl::Required
Definition: DeclObjC.h:144
clang::Decl::isInvalidDecl
bool isInvalidDecl() const
Definition: DeclBase.h:542
clang::InitializedEntity::InitializeResult
static InitializedEntity InitializeResult(SourceLocation ReturnLoc, QualType Type, bool NRVO)
Create the initialization entity for the result of a function.
Definition: Initialization.h:286
clang::ObjCPropertyDecl::findPropertyDecl
static ObjCPropertyDecl * findPropertyDecl(const DeclContext *DC, const IdentifierInfo *propertyID, ObjCPropertyQueryKind queryKind)
Lookup a property by name in the specified DeclContext.
Definition: DeclObjC.cpp:177
SemaInternal.h
clang::ObjCProtocolDecl::protocols
protocol_range protocols() const
Definition: DeclObjC.h:2129
clang::ParmVarDecl
Represents a parameter to a function.
Definition: Decl.h:1550
ExprCXX.h
Defines the clang::Expr interface and subclasses for C++ expressions.
clang::frontend::FixIt
Parse and apply any fixits to the source.
Definition: FrontendOptions.h:77
clang::Qualifiers
The collection of all-type qualifiers we support.
Definition: Type.h:141
clang::NamedDecl::getIdentifier
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:270
clang::ObjCDeclSpec::DQ_PR_unsafe_unretained
Definition: DeclSpec.h:823
CollectImmediateProperties
static void CollectImmediateProperties(ObjCContainerDecl *CDecl, ObjCContainerDecl::PropertyMap &PropMap, ObjCContainerDecl::PropertyMap &SuperPropMap, bool CollectClassPropsOnly=false, bool IncludeProtocols=true)
CollectImmediateProperties - This routine collects all properties in the class and its conforming pro...
Definition: SemaObjCProperty.cpp:1701
clang::NamedDecl::getDeclName
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:298
clang::ObjCContainerDecl::instance_properties
instprop_range instance_properties() const
Definition: DeclObjC.h:1003
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:58
clang::ObjCDeclSpec::getSetterNameLoc
SourceLocation getSetterNameLoc() const
Definition: DeclSpec.h:883
clang::ObjCMethodDecl::Optional
Definition: DeclObjC.h:144
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:155
clang::DeclContextLookupResult
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1187
clang::ObjCContainerDecl::getClassMethod
ObjCMethodDecl * getClassMethod(Selector Sel, bool AllowHidden=false) const
Definition: DeclObjC.h:1092
clang::ObjCPropertyDecl::Required
Definition: DeclObjC.h:761
clang::ObjCDeclSpec::DQ_PR_nullability
Definition: DeclSpec.h:824
clang::ObjCMethodFamily
ObjCMethodFamily
A family of Objective-C methods.
Definition: IdentifierTable.h:611
clang::OMF_retainCount
Definition: IdentifierTable.h:632
clang::ObjCDeclSpec::DQ_PR_retain
Definition: DeclSpec.h:816
clang::ObjCContainerDecl::instance_methods
instmeth_range instance_methods() const
Definition: DeclObjC.h:1054
clang::Qualifiers::ObjCLifetime
ObjCLifetime
Definition: Type.h:156
clang::ObjCContainerDecl::methods
method_range methods() const
Definition: DeclObjC.h:1037
clang::Token
Token - This structure provides full information about a lexed token.
Definition: Token.h:35
clang::ObjCContainerDecl::properties
prop_range properties() const
Definition: DeclObjC.h:988
Category
int Category
Definition: Format.cpp:1632
clang::ASTContext::Idents
IdentifierTable & Idents
Definition: ASTContext.h:566
clang::FieldDeclarator
This little struct is used to capture information about structure field declarators, which is basically just a bitfield size.
Definition: DeclSpec.h:2490
clang::VK_RValue
An r-value expression (a pr-value in the C++11 taxonomy) produces a temporary value.
Definition: Specifiers.h:110
clang::ObjCPropertyDecl::isClassProperty
bool isClassProperty() const
Definition: DeclObjC.h:879
clang::ObjCMethodDecl::getMethodFamily
ObjCMethodFamily getMethodFamily() const
Determines the family of this method.
Definition: DeclObjC.cpp:986
clang::ObjCInterfaceDecl::collectPropertiesToImplement
void collectPropertiesToImplement(PropertyMap &PM, PropertyDeclOrder &PO) const override
This routine collects list of properties to be implemented in the class.
Definition: DeclObjC.cpp:393
clang::Declarator::setObjCWeakProperty
void setObjCWeakProperty(bool Val=true)
Definition: DeclSpec.h:2439
clang::ObjCRuntime::isNonFragile
bool isNonFragile() const
Does this runtime follow the set of implied behaviors for a "non-fragile" ABI?
Definition: ObjCRuntime.h:82
clang::ObjCContainerDecl
ObjCContainerDecl - Represents a container for method declarations.
Definition: DeclObjC.h:969
clang::format::Tok
const FormatToken & Tok
Definition: BreakableToken.h:244
clang::ObjCDeclSpec::DQ_PR_copy
Definition: DeclSpec.h:817
clang::ObjCPropertyImplDecl::Create
static ObjCPropertyImplDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation atLoc, SourceLocation L, ObjCPropertyDecl *property, Kind PK, ObjCIvarDecl *ivarDecl, SourceLocation ivarLoc)
Definition: DeclObjC.cpp:2247
clang::Sema::CheckAssignmentConstraints
AssignConvertType CheckAssignmentConstraints(SourceLocation Loc, QualType LHSType, QualType RHSType)
CheckAssignmentConstraints - Perform type checking for assignment, argument passing, variable initialization, and function return values.
Definition: SemaExpr.cpp:7772
clang::NullabilityKind::Unspecified
Whether values of this type can be null is (explicitly) unspecified.
clang::ObjCPropertyDecl::getPropertyAttributes
PropertyAttributeKind getPropertyAttributes() const
Definition: DeclObjC.h:840
clang::ObjCInterfaceDecl::isObjCRequiresPropertyDefs
const ObjCInterfaceDecl * isObjCRequiresPropertyDefs() const
isObjCRequiresPropertyDefs - Checks that a class or one of its super classes must not be auto-synthes...
Definition: DeclObjC.cpp:423
clang::Sema::MarkDeclRefReferenced
void MarkDeclRefReferenced(DeclRefExpr *E, const Expr *Base=nullptr)
Perform reference-marking and odr-use handling for a DeclRefExpr.
Definition: SemaExpr.cpp:15736
clang::ObjCPropertyDecl::OBJC_PR_nonatomic
Definition: DeclObjC.h:741
DiagnoseUnimplementedAccessor
static void DiagnoseUnimplementedAccessor(Sema &S, ObjCInterfaceDecl *PrimaryClass, Selector Method, ObjCImplDecl *IMPDecl, ObjCContainerDecl *CDecl, ObjCCategoryDecl *C, ObjCPropertyDecl *Prop, llvm::SmallPtrSet< const ObjCMethodDecl *, 8 > &SMap)
Definition: SemaObjCProperty.cpp:1939
clang::ObjCPropertyDecl::isReadOnly
bool isReadOnly() const
isReadOnly - Return true iff the property has a setter.
Definition: DeclObjC.h:863
ExprObjC.h
clang::NullabilityKind::NonNull
Values of this type can never be null.
clang::ObjCProtocolDecl::getDefinition
ObjCProtocolDecl * getDefinition()
Retrieve the definition of this protocol, if any.
Definition: DeclObjC.h:2210
clang::Scope
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:41
clang::declaresSameEntity
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
Definition: DeclBase.h:1158
clang::frontend::CPlusPlus
Definition: LangStandard.h:26
clang::ObjCProtocolDecl
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2064
clang::Sema::PP
Preprocessor & PP
Definition: Sema.h:323
clang::Sema::getLangOpts
const LangOptions & getLangOpts() const
Definition: Sema.h:1231
clang::LangOptions::GCOnly
Definition: LangOptions.h:54
clang::ObjCPropertyDecl::getPropertyImplementation
PropertyControl getPropertyImplementation() const
Definition: DeclObjC.h:933
clang::ObjCInterfaceDecl
Represents an ObjC class declaration.
Definition: DeclObjC.h:1172
clang::Sema::CreatePropertyDecl
ObjCPropertyDecl * CreatePropertyDecl(Scope *S, ObjCContainerDecl *CDecl, SourceLocation AtLoc, SourceLocation LParenLoc, FieldDeclarator &FD, Selector GetterSel, SourceLocation GetterNameLoc, Selector SetterSel, SourceLocation SetterNameLoc, const bool isReadWrite, const unsigned Attributes, const unsigned AttributesAsWritten, QualType T, TypeSourceInfo *TSI, tok::ObjCKeywordKind MethodImplKind, DeclContext *lexicalDC=nullptr)
Called by ActOnProperty and HandlePropertyInClassExtension to handle creating the ObjcPropertyDecl fo...
Definition: SemaObjCProperty.cpp:565
clang::ObjCMethodDecl::getReturnType
QualType getReturnType() const
Definition: DeclObjC.h:323
llvm::SmallString
Definition: LLVM.h:35
ASTMutationListener.h
clang::Declarator::getIdentifier
IdentifierInfo * getIdentifier() const
Definition: DeclSpec.h:2127
clang::Sema::LangOpts
const LangOptions & LangOpts
Definition: Sema.h:322
clang::Qualifiers::OCL_ExplicitNone
This object can be modified without requiring retains or releases.
Definition: Type.h:162
clang::Sema::AtomicPropertySetterGetterRules
void AtomicPropertySetterGetterRules(ObjCImplDecl *IMPDecl, ObjCInterfaceDecl *IDecl)
AtomicPropertySetterGetterRules - This routine enforces the rule (via warning) when atomic property h...
Definition: SemaObjCProperty.cpp:2113
clang::ObjCPropertyImplDecl::setGetterCXXConstructor
void setGetterCXXConstructor(Expr *getterCXXConstructor)
Definition: DeclObjC.h:2853
clang::Sema::AddInstanceMethodToGlobalPool
void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false)
AddInstanceMethodToGlobalPool - All instance methods in a translation unit are added to a global pool...
Definition: Sema.h:3621
clang::DeclContext::lookup
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Definition: DeclBase.cpp:1595
clang::Sema::CheckObjCMethodOverrides
void CheckObjCMethodOverrides(ObjCMethodDecl *ObjCMethod, ObjCInterfaceDecl *CurrentClass, ResultTypeCompatibilityKind RTC)
Definition: SemaDeclObjC.cpp:4299
clang::ObjCPropertyImplDecl
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
Definition: DeclObjC.h:2759
clang::Decl::hasAttr
bool hasAttr() const
Definition: DeclBase.h:531
llvm::str
return Out str()
clang::Sema
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:278
AddPropertyAttrs
static void AddPropertyAttrs(Sema &S, ObjCMethodDecl *PropertyMethod, ObjCPropertyDecl *Property)
AddPropertyAttrs - Propagates attributes from a property to the implicitly-declared getter or setter ...
Definition: SemaObjCProperty.cpp:2300
clang::ObjCRuntime::isFragile
bool isFragile() const
The inverse of isNonFragile(): does this runtime follow the set of implied behaviors for a "fragile" ...
Definition: ObjCRuntime.h:97
clang::Decl::getAvailability
AvailabilityResult getAvailability(std::string *Message=nullptr, VersionTuple EnclosingVersion=VersionTuple(), StringRef *RealizedPlatform=nullptr) const
Determine the availability of the given declaration.
Definition: DeclBase.cpp:589
clang::Sema::SelectorSet
llvm::SmallPtrSet< Selector, 8 > SelectorSet
Definition: Sema.h:3439
clang::ImplicitCastExpr::Create
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat)
Definition: Expr.cpp:1844
clang::ObjCDeclSpec::DQ_PR_assign
Definition: DeclSpec.h:814
clang::Qualifiers::addObjCLifetime
void addObjCLifetime(ObjCLifetime type)
Definition: Type.h:333
clang::ObjCIvarDecl::getUsageType
QualType getUsageType(QualType objectType) const
Retrieve the type of this instance variable when viewed as a member of a specific object type...
Definition: DeclObjC.cpp:1814
clang::ASTContext::getTrivialTypeSourceInfo
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location, which defaults to the empty location.
Definition: ASTContext.cpp:2600
clang::ObjCPropertyDecl::OBJC_PR_atomic
Definition: DeclObjC.h:743
clang::TypeLoc::getBeginLoc
SourceLocation getBeginLoc() const
Get the begin source location.
Definition: TypeLoc.cpp:190
clang::QualType::isObjCGCStrong
bool isObjCGCStrong() const
true when Type is objc&#39;s strong.
Definition: Type.h:1053
clang::Expr
This represents one expression.
Definition: Expr.h:106
clang::ObjCInterfaceDecl::known_extensions
known_extensions_range known_extensions() const
Definition: DeclObjC.h:1761
clang::ObjCMethodDecl::Create
static ObjCMethodDecl * Create(ASTContext &C, SourceLocation beginLoc, SourceLocation endLoc, Selector SelInfo, QualType T, TypeSourceInfo *ReturnTInfo, DeclContext *contextDecl, bool isInstance=true, bool isVariadic=false, bool isPropertyAccessor=false, bool isImplicitlyDeclared=false, bool isDefined=false, ImplementationControl impControl=None, bool HasRelatedResultType=false)
Definition: DeclObjC.cpp:810
clang::ObjCPropertyDecl::getSetterName
Selector getSetterName() const
Definition: DeclObjC.h:914
clang::ObjCContainerDecl::HasUserDeclaredSetterMethod
bool HasUserDeclaredSetterMethod(const ObjCPropertyDecl *P) const
This routine returns &#39;true&#39; if a user declared setter method was found in the class, its protocols, its super classes or categories.
Definition: DeclObjC.cpp:124
clang::ObjCPropertyDecl::getDefaultSynthIvarName
IdentifierInfo * getDefaultSynthIvarName(ASTContext &Ctx) const
Get the default name of the synthesized ivar.
Definition: DeclObjC.cpp:225
clang::Type::isObjCARCImplicitlyUnretainedType
bool isObjCARCImplicitlyUnretainedType() const
Determines if this type, which must satisfy isObjCLifetimeType(), is implicitly __unsafe_unretained r...
Definition: Type.cpp:3883
clang::ObjCPropertyDecl::getTypeSourceInfo
TypeSourceInfo * getTypeSourceInfo() const
Definition: DeclObjC.h:827
clang::OMF_new
Definition: IdentifierTable.h:623
clang::OMF_retain
Definition: IdentifierTable.h:631
clang::OMF_copy
Definition: IdentifierTable.h:620
clang::Type::isObjCRetainableType
bool isObjCRetainableType() const
Definition: Type.cpp:3921
makePropertyAttributesAsWritten
static ObjCPropertyDecl::PropertyAttributeKind makePropertyAttributesAsWritten(unsigned Attributes)
Definition: SemaObjCProperty.cpp:282
clang::Decl::setInvalidDecl
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
Definition: DeclBase.cpp:132
hasWrittenStorageAttribute
static bool hasWrittenStorageAttribute(ObjCPropertyDecl *Prop, ObjCPropertyQueryKind QueryKind)
Determine whether any storage attributes were written on the property.
Definition: SemaObjCProperty.cpp:1009
clang::DeclContextLookupResult::size
size_t size() const
Definition: DeclBase.h:1233
Preprocessor.h
Defines the clang::Preprocessor interface.
clang::Decl::getDeclContext
DeclContext * getDeclContext()
Definition: DeclBase.h:427
clang::ObjCPropertyDecl::OBJC_PR_weak
Definition: DeclObjC.h:744
clang::OMF_mutableCopy
Definition: IdentifierTable.h:622
clang::ObjCInterfaceDecl::getSuperClass
ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.cpp:338
Lexer.h
clang::Sema::ProcessDeclAttributes
void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD)
clang::TokenValue
Stores token information for comparing actual tokens with predefined values.
Definition: Preprocessor.h:86
clang::OMF_release
Definition: IdentifierTable.h:630
clang::ObjCInterfaceDecl::FindPropertyVisibleInPrimaryClass
ObjCPropertyDecl * FindPropertyVisibleInPrimaryClass(IdentifierInfo *PropertyId, ObjCPropertyQueryKind QueryKind) const
FindPropertyVisibleInPrimaryClass - Finds declaration of the property with name &#39;PropertyId&#39; in the p...
Definition: DeclObjC.cpp:369
clang::Sema::RequireCompleteType
bool RequireCompleteType(SourceLocation Loc, QualType T, TypeDiagnoser &Diagnoser)
Ensure that the type T is a complete type.
Definition: SemaType.cpp:7603
clang::ObjCMethodDecl::param_iterator
ParmVarDecl *const * param_iterator
Definition: DeclObjC.h:344
clang::SplitQualType
A std::pair-like structure for storing a qualified type split into its local qualifiers and its local...
Definition: Type.h:577
clang::AttributedType::stripOuterNullability
static Optional< NullabilityKind > stripOuterNullability(QualType &T)
Strip off the top-level nullability annotation on the given type, if it&#39;s there.
Definition: Type.cpp:3833
clang::ObjCInterfaceDecl::lookupInstanceVariable
ObjCIvarDecl * lookupInstanceVariable(IdentifierInfo *IVarName, ObjCInterfaceDecl *&ClassDeclared)
Definition: DeclObjC.cpp:621
clang::LangOptions::ObjCRuntime
clang::ObjCRuntime ObjCRuntime
Definition: LangOptions.h:207
clang::ObjCImplDecl::property_impls
propimpl_range property_impls() const
Definition: DeclObjC.h:2467
clang::SplitQualType::Quals
Qualifiers Quals
The local qualifiers.
Definition: Type.h:582
clang::ObjCContainerDecl::ProtocolPropertySet
llvm::SmallDenseSet< const ObjCProtocolDecl *, 8 > ProtocolPropertySet
Definition: DeclObjC.h:1106
clang::ActionResult::isInvalid
bool isInvalid() const
Definition: Ownership.h:170
clang::ObjCMethodDecl::isInstanceMethod
bool isInstanceMethod() const
Definition: DeclObjC.h:422
clang::Sema::getPreprocessor
Preprocessor & getPreprocessor() const
Definition: Sema.h:1237
clang::ObjCDeclSpec::DQ_PR_setter
Definition: DeclSpec.h:819
clang::ObjCMethodDecl::getSelector
Selector getSelector() const
Definition: DeclObjC.h:321
clang::ObjCPropertyDecl::getType
QualType getType() const
Definition: DeclObjC.h:829
SM
const SourceManager & SM
Definition: Format.cpp:1490
getIdentifier
static StringRef getIdentifier(const Token &Tok)
Definition: ParsePragma.cpp:1160
clang::Sema::RTC_Unknown
Definition: Sema.h:8343
clang::tok::ObjCKeywordKind
ObjCKeywordKind
Provides a namespace for Objective-C keywords which start with an &#39;@&#39;.
Definition: TokenKinds.h:41
clang::ObjCDeclSpec::DQ_PR_readwrite
Definition: DeclSpec.h:815
clang::ASTContext::getObjCGCQualType
QualType getObjCGCQualType(QualType T, Qualifiers::GC gcAttr) const
Return the uniqued reference to the type for an Objective-C gc-qualified type.
Definition: ASTContext.cpp:2693
clang::ASTContext::getAttributedType
QualType getAttributedType(attr::Kind attrKind, QualType modifiedType, QualType equivalentType)
Definition: ASTContext.cpp:3929
clang::QualType::split
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
Definition: Type.h:6080
clang::RecordType::getDecl
RecordDecl * getDecl() const
Definition: Type.h:4380
clang::ObjCIvarDecl::Private
Definition: DeclObjC.h:1950
clang::Qualifiers::OCL_None
There is no lifetime qualification on this type.
Definition: Type.h:158
clang::DeclContext::makeDeclVisibleInContext
void makeDeclVisibleInContext(NamedDecl *D)
Makes a declaration visible within this context.
Definition: DeclBase.cpp:1785
clang::Qualifiers::OCL_Strong
Assigning into this object requires the old value to be released and the new value to be retained...
Definition: Type.h:169
Kind
Kind
Definition: ChrootChecker.cpp:29
clang::ActionResult
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
Definition: Ownership.h:157
clang::DiagnosticLevelMask::Note
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:88
clang::ObjCIvarDecl::getSynthesize
bool getSynthesize() const
Definition: DeclObjC.h:1991
clang::IdentifierTable::get
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
Definition: IdentifierTable.h:519
clang::ObjCPropertyQueryKind
ObjCPropertyQueryKind
Definition: DeclObjC.h:717
clang::ObjCPropertyDecl::OBJC_PR_null_resettable
Definition: DeclObjC.h:750
clang::ObjCDeclSpec::DQ_PR_getter
Definition: DeclSpec.h:813
clang::ObjCDeclSpec::DQ_PR_atomic
Definition: DeclSpec.h:820
clang::ObjCPropertyDecl::setPropertyAttributesAsWritten
void setPropertyAttributesAsWritten(PropertyAttributeKind PRVal)
Definition: DeclObjC.h:856
Initialization.h
getImpliedARCOwnership
static Qualifiers::ObjCLifetime getImpliedARCOwnership(ObjCPropertyDecl::PropertyAttributeKind attrs, QualType type)
getImpliedARCOwnership - Given a set of property attributes and a type, infer an expected lifetime...
Definition: SemaObjCProperty.cpp:39
clang::ObjCDeclSpec::getPropertyAttributes
ObjCPropertyAttributeKind getPropertyAttributes() const
Definition: DeclSpec.h:843
clang::ObjCCategoryDecl
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2280
clang::ASTContext::VoidTy
CanQualType VoidTy
Definition: ASTContext.h:1016
llvm::SmallVector
Definition: LLVM.h:36
clang::Sema::DiagnoseUnimplementedProperties
void DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl *IMPDecl, ObjCContainerDecl *CDecl, bool SynthesizeProperties)
DiagnoseUnimplementedProperties - This routine warns on those properties which must be implemented by...
Definition: SemaObjCProperty.cpp:1977
clang::ObjCPropertyDecl
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:729
clang::ObjCInterfaceDecl::lookupPropertyAccessor
ObjCMethodDecl * lookupPropertyAccessor(const Selector Sel, const ObjCCategoryDecl *Cat, bool IsClassProperty) const
Lookup a setter or getter in the class hierarchy, including in all categories except for category pas...
Definition: DeclObjC.h:1869
clang::Sema::LookupProtocol
ObjCProtocolDecl * LookupProtocol(IdentifierInfo *II, SourceLocation IdLoc, RedeclarationKind Redecl=NotForRedeclaration)
Find the protocol with the given name, if any.
Definition: SemaLookup.cpp:2825
clang::ObjCImplDecl::FindPropertyImplIvarDecl
ObjCPropertyImplDecl * FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const
FindPropertyImplIvarDecl - This method lookup the ivar in the list of properties implemented in this ...
Definition: DeclObjC.cpp:2098
clang::ObjCPropertyDecl::OBJC_PR_nullability
Indicates that the nullability of the type was spelled with a property attribute rather than a type q...
Definition: DeclObjC.h:749
clang::ObjCPropertyDecl::OBJC_PR_copy
Definition: DeclObjC.h:740
clang::Qualifiers::OCL_Autoreleasing
Assigning into this object requires a lifetime extension.
Definition: Type.h:175
clang::RecordDecl::hasFlexibleArrayMember
bool hasFlexibleArrayMember() const
Definition: Decl.h:3647
clang::ASTContext::hasSameUnqualifiedType
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
Definition: ASTContext.h:2293
clang::MultiVersionKind::None
clang::ObjCDeclSpec::DQ_PR_readonly
Definition: DeclSpec.h:812
clang::Sema::DiagnoseOwningPropertyGetterSynthesis
void DiagnoseOwningPropertyGetterSynthesis(const ObjCImplementationDecl *D)
Definition: SemaObjCProperty.cpp:2208
clang::LangOptions::NonGC
Definition: LangOptions.h:54
clang::ImplicitParamDecl
Definition: Decl.h:1486
clang::ObjCPropertyImplDecl::setSetterCXXAssignment
void setSetterCXXAssignment(Expr *setterCXXAssignment)
Definition: DeclObjC.h:2861
checkARCPropertyImpl
static void checkARCPropertyImpl(Sema &S, SourceLocation propertyImplLoc, ObjCPropertyDecl *property, ObjCIvarDecl *ivar)
Definition: SemaObjCProperty.cpp:715
clang::QualType::isObjCGCWeak
bool isObjCGCWeak() const
true when Type is objc&#39;s weak.
Definition: Type.h:1048
clang::ASTContext::propertyTypesAreCompatible
bool propertyTypesAreCompatible(QualType, QualType)
Definition: ASTContext.cpp:8448
clang::Sema::PerformCopyInitialization
ExprResult PerformCopyInitialization(const InitializedEntity &Entity, SourceLocation EqualLoc, ExprResult Init, bool TopLevelOfInitList=false, bool AllowExplicit=false)
Definition: SemaInit.cpp:9125
clang::ObjCSubstitutionContext::Property
The type of a property.
clang::ObjCImplDecl::getClassInterface
const ObjCInterfaceDecl * getClassInterface() const
Definition: DeclObjC.h:2440
clang::Decl::redecls
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Definition: DeclBase.h:941
clang::ParmVarDecl::Create
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
Definition: Decl.cpp:2535
clang::Qualifiers::Weak
Definition: Type.h:152
setImpliedPropertyAttributeForReadOnlyProperty
static void setImpliedPropertyAttributeForReadOnlyProperty(ObjCPropertyDecl *property, ObjCIvarDecl *ivar)
setImpliedPropertyAttributeForReadOnlyProperty - This routine evaludates life-time attributes for a &#39;...
Definition: SemaObjCProperty.cpp:795
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
clang::SourceLocation::isValid
bool isValid() const
Return true if this is a valid SourceLocation object.
Definition: SourceLocation.h:108
clang::ObjCPropertyDecl::OBJC_PR_readonly
Definition: DeclObjC.h:735
clang::ObjCContainerDecl::FindPropertyDeclaration
ObjCPropertyDecl * FindPropertyDeclaration(const IdentifierInfo *PropertyId, ObjCPropertyQueryKind QueryKind) const
FindPropertyDeclaration - Finds declaration of the property given its name in &#39;PropertyId&#39; and return...
Definition: DeclObjC.cpp:236
clang::Sema::diagnoseNullResettableSynthesizedSetters
void diagnoseNullResettableSynthesizedSetters(const ObjCImplDecl *impDecl)
Diagnose any null-resettable synthesized setters.
Definition: SemaObjCProperty.cpp:2085
clang::ObjCPropertyDecl::setGetterName
void setGetterName(Selector Sel, SourceLocation Loc=SourceLocation())
Definition: DeclObjC.h:909
clang::Sema::AbstractSynthesizedIvarType
Definition: Sema.h:6120
clang::DeclContext
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1262
SuperClassImplementsProperty
static bool SuperClassImplementsProperty(ObjCInterfaceDecl *IDecl, ObjCPropertyDecl *Prop)
Definition: SemaObjCProperty.cpp:1811
clang::ObjCPropertyDecl::getPropertyAttributesAsWritten
PropertyAttributeKind getPropertyAttributesAsWritten() const
Definition: DeclObjC.h:852
clang::ObjCImplDecl
Definition: DeclObjC.h:2425
clang::ObjCRuntime
The basic abstraction for the target Objective-C runtime.
Definition: ObjCRuntime.h:28
clang::Decl::attrs
attr_range attrs() const
Definition: DeclBase.h:490
type
clang::Sema::CheckARCMethodDecl
bool CheckARCMethodDecl(ObjCMethodDecl *method)
Check a method declaration for compatibility with the Objective-C ARC conventions.
Definition: SemaDeclObjC.cpp:225
clang::ObjCPropertyDecl::OBJC_PR_retain
Definition: DeclObjC.h:739
clang::ObjCContainerDecl::PropertyMap
llvm::DenseMap< std::pair< IdentifierInfo *, unsigned >, ObjCPropertyDecl * > PropertyMap
Definition: DeclObjC.h:1105
clang::Qualifiers::hasObjCLifetime
bool hasObjCLifetime() const
Definition: Type.h:325
clang::ObjCDeclSpec::DQ_PR_strong
Definition: DeclSpec.h:822
clang::FieldDeclarator::D
Declarator D
Definition: DeclSpec.h:2491
clang::ObjCPropertyDecl::Optional
Definition: DeclObjC.h:761
clang::ObjCInterfaceDecl::hasDesignatedInitializers
bool hasDesignatedInitializers() const
Returns true if this interface decl contains at least one initializer marked with the &#39;objc_designate...
Definition: DeclObjC.cpp:1522
clang::SourceLocation::isMacroID
bool isMacroID() const
Definition: SourceLocation.h:101
clang::ObjCObjectPointerType
Represents a pointer to an Objective C object.
Definition: Type.h:5794
clang::ObjCIvarDecl::Create
static ObjCIvarDecl * Create(ASTContext &C, ObjCContainerDecl *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, AccessControl ac, Expr *BW=nullptr, bool synthesized=false)
Definition: DeclObjC.cpp:1748
clang::ObjCImplementationDecl
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition: DeclObjC.h:2552
clang::RecordType
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4370
clang::ObjCPropertyDecl::overwritePropertyAttributes
void overwritePropertyAttributes(unsigned PRVal)
Definition: DeclObjC.h:848
clang::Decl::getAttr
T * getAttr() const
Definition: DeclBase.h:527
clang::ObjCDeclSpec::getGetterNameLoc
SourceLocation getGetterNameLoc() const
Definition: DeclSpec.h:875
clang::ObjCPropertyDecl::OBJC_PR_strong
Definition: DeclObjC.h:745
clang::ASTContext::hasSameType
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2269
clang::ObjCPropertyDecl::OBJC_PR_setter
Definition: DeclObjC.h:742
clang::FixItHint::CreateInsertion
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
Definition: Diagnostic.h:92
clang::DeclContext::addDecl
void addDecl(Decl *D)
Add the declaration D into this context.
Definition: DeclBase.cpp:1507
clang::ASTContext::canAssignObjCInterfaces
bool canAssignObjCInterfaces(const ObjCObjectPointerType *LHSOPT, const ObjCObjectPointerType *RHSOPT)
canAssignObjCInterfaces - Return true if the two interface types are compatible for assignment from R...
Definition: ASTContext.cpp:7998
clang::ObjCInterfaceDecl::lookupMethod
ObjCMethodDecl * lookupMethod(Selector Sel, bool isInstance, bool shallowCategoryLookup=false, bool followSuper=true, const ObjCCategoryDecl *C=nullptr) const
lookupMethod - This method returns an instance/class method by looking in the class, its categories, and its super classes (using a linear search).
Definition: DeclObjC.cpp:683
clang::ObjCPropertyDecl::setSetterName
void setSetterName(Selector Sel, SourceLocation Loc=SourceLocation())
Definition: DeclObjC.h:917
clang::ObjCPropertyDecl::OBJC_PR_getter
Definition: DeclObjC.h:736
checkAtomicPropertyMismatch
static void checkAtomicPropertyMismatch(Sema &S, ObjCPropertyDecl *OldProperty, ObjCPropertyDecl *NewProperty, bool PropagateAtomicity)
Check for a mismatch in the atomicity of the given properties.
Definition: SemaObjCProperty.cpp:344
clang::ObjCIvarRefExpr
ObjCIvarRefExpr - A reference to an ObjC instance variable.
Definition: ExprObjC.h:513
clang::ASTContext::getSourceManager
SourceManager & getSourceManager()
Definition: ASTContext.h:662
clang::Type::isObjCObjectType
bool isObjCObjectType() const
Definition: Type.h:6397
clang::ObjCCategoryDecl::IsClassExtension
bool IsClassExtension() const
Definition: DeclObjC.h:2390
clang::Declarator::getIdentifierLoc
SourceLocation getIdentifierLoc() const
Definition: DeclSpec.h:2133
clang::ASTContext::getCanonicalType
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2253
clang::ObjCPropertyDecl::OBJC_PR_readwrite
Definition: DeclObjC.h:738
clang::TypeSourceInfo::getTypeLoc
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:238
clang::ObjCPropertyImplDecl::Synthesize
Definition: DeclObjC.h:2762
LocPropertyAttribute
static bool LocPropertyAttribute(ASTContext &Context, const char *attrName, SourceLocation LParenLoc, SourceLocation &Loc)
Definition: SemaObjCProperty.cpp:314
clang::Qualifiers::OCL_Weak
Reading or writing from this object requires a barrier call.
Definition: Type.h:172
clang::Sema::MaybeCreateExprWithCleanups
Expr * MaybeCreateExprWithCleanups(Expr *SubExpr)
MaybeCreateExprWithCleanups - If the current full-expression requires any cleanups, surround it with a ExprWithCleanups node.
Definition: SemaExprCXX.cpp:6503
clang::Sema::Compatible
Compatible - the types are compatible according to the standard.
Definition: Sema.h:9524
clang::ObjCImplDecl::FindPropertyImplDecl
ObjCPropertyImplDecl * FindPropertyImplDecl(IdentifierInfo *propertyId, ObjCPropertyQueryKind queryKind) const
FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl added to the list of thos...
Definition: DeclObjC.cpp:2110
clang::ObjCPropertyDecl::OBJC_PR_class
Definition: DeclObjC.h:751
clang::SourceLocation::isInvalid
bool isInvalid() const
Definition: SourceLocation.h:109
clang::ObjCIvarDecl
ObjCIvarDecl - Represents an ObjC instance variable.
Definition: DeclObjC.h:1945
clang::AttrSyntax::C
deducePropertyOwnershipFromType
static unsigned deducePropertyOwnershipFromType(Sema &S, QualType T)
Definition: SemaObjCProperty.cpp:131
clang::ObjCDeclSpec::DQ_PR_weak
Definition: DeclSpec.h:821
clang::ObjCPropertyDecl::OBJC_PR_assign
Definition: DeclObjC.h:737
clang::Sema::CurContext
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Definition: Sema.h:336
clang::diag::kind
unsigned kind
All of the diagnostics that can be emitted by the frontend.
Definition: DiagnosticIDs.h:61
clang::FixItHint::CreateReplacement
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string...
Definition: Diagnostic.h:129
clang::Decl::addAttr
void addAttr(Attr *A)
Definition: DeclBase.cpp:840
clang::ObjCPropertyDecl::setPropertyAttributes
void setPropertyAttributes(PropertyAttributeKind PRVal)
Definition: DeclObjC.h:844
clang::OMF_init
Definition: IdentifierTable.h:621
clang::Sema::DiagnosePropertyMismatch
void DiagnosePropertyMismatch(ObjCPropertyDecl *Property, ObjCPropertyDecl *SuperProperty, const IdentifierInfo *Name, bool OverridingProtocolProperty)
DiagnosePropertyMismatch - Compares two properties for their attributes and types and warns on a vari...
Definition: SemaObjCProperty.cpp:1577
clang::NamedDecl::getName
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:276
clang::ObjCInterfaceDecl::isArcWeakrefUnavailable
bool isArcWeakrefUnavailable() const
isArcWeakrefUnavailable - Checks for a class or one of its super classes to be incompatible with __we...
Definition: DeclObjC.cpp:413
clang::ObjCDeclSpec::DQ_PR_null_resettable
Definition: DeclSpec.h:825
SelectPropertyForSynthesisFromProtocols
static ObjCPropertyDecl * SelectPropertyForSynthesisFromProtocols(Sema &S, SourceLocation AtLoc, ObjCInterfaceDecl *ClassDecl, ObjCPropertyDecl *Property)
SelectPropertyForSynthesisFromProtocols - Finds the most appropriate property declaration that should...
Definition: SemaObjCProperty.cpp:834
clang::Sema::DiagnosePropertyAccessorMismatch
bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD, ObjCMethodDecl *Getter, SourceLocation Loc)
Definition: SemaObjCProperty.cpp:1655
clang::Sema::DefaultSynthesizeProperties
void DefaultSynthesizeProperties(Scope *S, ObjCImplDecl *IMPDecl, ObjCInterfaceDecl *IDecl, SourceLocation AtEnd)
DefaultSynthesizeProperties - This routine default synthesizes all properties which must be synthesiz...
Definition: SemaObjCProperty.cpp:1834
OwnershipMask
static const unsigned OwnershipMask
Definition: SemaObjCProperty.cpp:156
clang::DeclRefExpr
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1041
clang::ObjCImplDecl::addPropertyImplementation
void addPropertyImplementation(ObjCPropertyImplDecl *property)
Definition: DeclObjC.cpp:2073
clang::ActionResult::getAs
T * getAs()
Definition: Ownership.h:175
CheckPropertyAgainstProtocol
static void CheckPropertyAgainstProtocol(Sema &S, ObjCPropertyDecl *Prop, ObjCProtocolDecl *Proto, llvm::SmallPtrSetImpl< ObjCProtocolDecl *> &Known)
Check this Objective-C property against a property declared in the given protocol.
Definition: SemaObjCProperty.cpp:110
clang::ValueDecl::getType
QualType getType() const
Definition: Decl.h:648
true
#define true
Definition: stdbool.h:32
clang::VK_LValue
An l-value expression is a reference to an object with independent storage.
Definition: Specifiers.h:114
clang::SourceRange
A trivial tuple used to represent a source range.
Definition: SourceLocation.h:198
clang::Sema::Context
ASTContext & Context
Definition: Sema.h:324
clang::Decl::setLexicalDeclContext
void setLexicalDeclContext(DeclContext *DC)
Definition: DeclBase.cpp:299
clang::ObjCPropertyDecl::getGetterMethodDecl
ObjCMethodDecl * getGetterMethodDecl() const
Definition: DeclObjC.h:922
clang::ASTContext::getObjCObjectPointerType
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
Definition: ASTContext.cpp:4687
clang::ObjCContainerDecl::getInstanceMethod
ObjCMethodDecl * getInstanceMethod(Selector Sel, bool AllowHidden=false) const
Definition: DeclObjC.h:1087
clang::Sema::BuildBinOp
ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr)
Definition: SemaExpr.cpp:12738
SMap
llvm::DenseMap< const Stmt *, CFGBlock * > SMap
Definition: CFGStmtMap.cpp:22
clang::ObjCIvarDecl::getAccessControl
AccessControl getAccessControl() const
Definition: DeclObjC.h:1984
clang::ObjCMethodDecl::isPropertyAccessor
bool isPropertyAccessor() const
Definition: DeclObjC.h:432
clang::ObjCPropertyDecl::getGetterName
Selector getGetterName() const
Definition: DeclObjC.h:906
clang::ObjCPropertyDecl::getLParenLoc
SourceLocation getLParenLoc() const
Definition: DeclObjC.h:824
clang::DeclContextLookupResult::empty
bool empty() const
Definition: DeclBase.h:1231
clang::ValueDecl::setType
void setType(QualType newType)
Definition: Decl.h:649
clang::ASTContext::getLangOpts
const LangOptions & getLangOpts() const
Definition: ASTContext.h:707
clang::ObjCCategoryImplDecl
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration...
Definition: DeclObjC.h:2499
clang::SourceManager
This class handles loading and caching of source files into memory.
Definition: SourceManager.h:582
checkPropertyDeclWithOwnership
static void checkPropertyDeclWithOwnership(Sema &S, ObjCPropertyDecl *property)
Check the internal consistency of a property declaration with an explicit ownership qualifier...
Definition: SemaObjCProperty.cpp:66
clang::ObjCPropertyDecl::OBJC_PR_unsafe_unretained
Definition: DeclObjC.h:746
clang::OMF_alloc
Definition: IdentifierTable.h:619
clang::Attr
Attr - This represents one attribute.
Definition: Attr.h:44
clang::Decl::getLocation
SourceLocation getLocation() const
Definition: DeclBase.h:418
clang::Sema::GetTypeForDeclarator
TypeSourceInfo * GetTypeForDeclarator(Declarator &D, Scope *S)
GetTypeForDeclarator - Convert the type for the specified declarator to Type instances.
Definition: SemaType.cpp:5170
clang::TypeSourceInfo::getType
QualType getType() const
Return the type wrapped by this type source info.
Definition: Decl.h:98
clang::SourceManager::getDecomposedLoc
std::pair< FileID, unsigned > getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
Definition: SourceManager.h:1196
clang::Preprocessor
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:125
clang::Decl::isUnavailable
bool isUnavailable(std::string *Message=nullptr) const
Determine whether this declaration is marked &#39;unavailable&#39;.
Definition: DeclBase.h:673
clang::OMF_autorelease
Definition: IdentifierTable.h:627
isIncompatiblePropertyAttribute
static bool isIncompatiblePropertyAttribute(unsigned Attr1, unsigned Attr2, ObjCPropertyDecl::PropertyAttributeKind Kind)
Definition: SemaObjCProperty.cpp:818
clang::QualType::getObjCLifetime
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
Definition: Type.h:1058
clang::ObjCInterfaceDecl::FindCategoryDeclaration
ObjCCategoryDecl * FindCategoryDeclaration(IdentifierInfo *CategoryId) const
FindCategoryDeclaration - Finds category declaration in the list of categories for this class and ret...
Definition: DeclObjC.cpp:1664