From 5b5d415d6c948b88c2d78644fe7183f32c3f91e0 Mon Sep 17 00:00:00 2001 From: Manman Ren Date: Mon, 15 Aug 2016 21:05:00 +0000 Subject: [PATCH] Objective-C diagnostics: isObjCNSObjectType should check through AttributedType. For the following example: typedef __attribute__((NSObject)) CGColorRef ColorAttrRef; @property (strong, nullable) ColorAttrRef color; The property type should be ObjC NSObject type and the compiler should not emit error: property with 'retain (or strong)' attribute must be of object type rdar://problem/27747154 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@278742 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/Type.cpp | 14 +++++++++++--- test/SemaObjC/nsobject-attribute.m | 2 ++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index 68e1fc09b8..4c1d4ec540 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -3686,10 +3686,18 @@ bool Type::isObjCARCImplicitlyUnretainedType() const { } bool Type::isObjCNSObjectType() const { - if (const TypedefType *typedefType = dyn_cast(this)) - return typedefType->getDecl()->hasAttr(); - return false; + const Type *cur = this; + while (true) { + if (const TypedefType *typedefType = dyn_cast(cur)) + return typedefType->getDecl()->hasAttr(); + + // Single-step desugar until we run out of sugar. + QualType next = cur->getLocallyUnqualifiedSingleStepDesugaredType(); + if (next.getTypePtr() == cur) return false; + cur = next.getTypePtr(); + } } + bool Type::isObjCIndependentClassType() const { if (const TypedefType *typedefType = dyn_cast(this)) return typedefType->getDecl()->hasAttr(); diff --git a/test/SemaObjC/nsobject-attribute.m b/test/SemaObjC/nsobject-attribute.m index 6bd2d5dabc..7c8d75d531 100644 --- a/test/SemaObjC/nsobject-attribute.m +++ b/test/SemaObjC/nsobject-attribute.m @@ -21,6 +21,8 @@ typedef struct CGColor * __attribute__((NSObject)) CGColorRefNoNSObject; // no-w @property (nonatomic, retain) CGColorRefNoNSObject color; // rdar://problem/12197822 @property (strong) __attribute__((NSObject)) CFTypeRef myObj; // no-warning +//rdar://problem/27747154 +@property (strong, nullable) CGColorRefNoNSObject color2; // no-warning @end void setProperty(id self, id value) { -- 2.40.0