diff options
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Sema/AttributeList.cpp | 1 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaDeclAttr.cpp | 15 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaType.cpp | 25 |
3 files changed, 40 insertions, 1 deletions
diff --git a/clang/lib/Sema/AttributeList.cpp b/clang/lib/Sema/AttributeList.cpp index afc23e9be20..5a8330bbfd7 100644 --- a/clang/lib/Sema/AttributeList.cpp +++ b/clang/lib/Sema/AttributeList.cpp @@ -107,6 +107,7 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) { return llvm::StringSwitch<AttributeList::Kind>(AttrName) .Case("weak", AT_weak) .Case("weakref", AT_weakref) + .Case("objc_arc_weak_reference_unavailable", AT_arc_weakref_unavailable) .Case("pure", AT_pure) .Case("mode", AT_mode) .Case("used", AT_used) diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 103976bc12f..adef528b0a4 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -1091,6 +1091,18 @@ static void handleUnavailableAttr(Sema &S, Decl *D, const AttributeList &Attr) { D->addAttr(::new (S.Context) UnavailableAttr(Attr.getLoc(), S.Context, Str)); } +static void handleArcWeakrefUnavailableAttr(Sema &S, Decl *D, + const AttributeList &Attr) { + unsigned NumArgs = Attr.getNumArgs(); + if (NumArgs > 0) { + S.Diag(Attr.getLoc(), diag::err_attribute_too_many_arguments) << 0; + return; + } + + D->addAttr(::new (S.Context) ArcWeakrefUnavailableAttr( + Attr.getLoc(), S.Context)); +} + static void handleAvailabilityAttr(Sema &S, Decl *D, const AttributeList &Attr) { IdentifierInfo *Platform = Attr.getParameterName(); @@ -3011,6 +3023,9 @@ static void ProcessInheritableDeclAttr(Sema &S, Scope *scope, Decl *D, case AttributeList::AT_MsStruct: handleMsStructAttr (S, D, Attr); break; case AttributeList::AT_section: handleSectionAttr (S, D, Attr); break; case AttributeList::AT_unavailable: handleUnavailableAttr (S, D, Attr); break; + case AttributeList::AT_arc_weakref_unavailable: + handleArcWeakrefUnavailableAttr (S, D, Attr); + break; case AttributeList::AT_unused: handleUnusedAttr (S, D, Attr); break; case AttributeList::AT_used: handleUsedAttr (S, D, Attr); break; case AttributeList::AT_visibility: handleVisibilityAttr (S, D, Attr); break; diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 14184220064..ae1ccf9886d 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -3207,7 +3207,30 @@ static bool handleObjCOwnershipTypeAttr(TypeProcessingState &state, attr.setInvalid(); return true; } - + + // Forbid __weak for class objects marked as + // objc_arc_weak_reference_unavailable + if (lifetime == Qualifiers::OCL_Weak) { + QualType T = type; + if (T->isReferenceType()) { + T = T->getAs<ReferenceType>()->getPointeeType(); + } + while (const PointerType *ptr = T->getAs<PointerType>()) + T = ptr->getPointeeType(); + if (const ObjCObjectPointerType *ObjT = T->getAs<ObjCObjectPointerType>()) { + ObjCInterfaceDecl *Class = ObjT->getInterfaceDecl(); + while (Class) { + if (Class->hasAttr<ArcWeakrefUnavailableAttr>()) { + S.Diag(attr.getLoc(), diag::err_arc_unsupported_weak_class); + S.Diag(ObjT->getInterfaceDecl()->getLocation(), + diag::note_class_declared); + break; + } + Class = Class->getSuperClass(); + } + } + } + return true; } |

