diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2010-03-30 22:40:11 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2010-03-30 22:40:11 +0000 |
commit | 842f07b065ac481fce9d82d55cb62e36bac6c921 (patch) | |
tree | a30fcadfb1998885b332c20ee511be310f5f94ea | |
parent | b5896c37922e09529e61db4b3dd946cf2ecb211e (diff) |
Recognize __attribute__((NSObject)) directly applied
on retain properties. (radar 7809468).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99951 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/Sema.h | 2 | ||||
-rw-r--r-- | lib/Sema/SemaObjCProperty.cpp | 16 | ||||
-rw-r--r-- | test/SemaObjC/nsobject-attribute.m | 6 |
3 files changed, 17 insertions, 7 deletions
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index d3e55f381e..1909607e2d 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -3777,7 +3777,7 @@ public: /// Ensure attributes are consistent with type. /// \param [in, out] Attributes The attributes to check; they will /// be modified to be consistent with \arg PropertyTy. - void CheckObjCPropertyAttributes(QualType PropertyTy, + void CheckObjCPropertyAttributes(DeclPtrTy PropertyPtrTy, SourceLocation Loc, unsigned &Attributes); void ProcessPropertyDecl(ObjCPropertyDecl *property, ObjCContainerDecl *DC); diff --git a/lib/Sema/SemaObjCProperty.cpp b/lib/Sema/SemaObjCProperty.cpp index 4dc734de8a..f815068fac 100644 --- a/lib/Sema/SemaObjCProperty.cpp +++ b/lib/Sema/SemaObjCProperty.cpp @@ -44,9 +44,6 @@ Sema::DeclPtrTy Sema::ActOnProperty(Scope *S, SourceLocation AtLoc, Diag(AtLoc, diag::error_reference_property); return DeclPtrTy(); } - // Validate the attributes on the @property. - CheckObjCPropertyAttributes(T, AtLoc, Attributes); - // Proceed with constructing the ObjCPropertDecls. ObjCContainerDecl *ClassDecl = cast<ObjCContainerDecl>(ClassCategory.getAs<Decl>()); @@ -60,10 +57,13 @@ Sema::DeclPtrTy Sema::ActOnProperty(Scope *S, SourceLocation AtLoc, isOverridingProperty, T, MethodImplKind); - return DeclPtrTy::make(CreatePropertyDecl(S, ClassDecl, AtLoc, FD, + DeclPtrTy Res = DeclPtrTy::make(CreatePropertyDecl(S, ClassDecl, AtLoc, FD, GetterSel, SetterSel, isAssign, isReadWrite, Attributes, T, MethodImplKind)); + // Validate the attributes on the @property. + CheckObjCPropertyAttributes(Res, AtLoc, Attributes); + return Res; } Sema::DeclPtrTy @@ -982,10 +982,13 @@ void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property, AddInstanceMethodToGlobalPool(SetterMethod); } -void Sema::CheckObjCPropertyAttributes(QualType PropertyTy, +void Sema::CheckObjCPropertyAttributes(DeclPtrTy PropertyPtrTy, SourceLocation Loc, unsigned &Attributes) { // FIXME: Improve the reported location. + Decl *PDecl = PropertyPtrTy.getAs<Decl>(); + ObjCPropertyDecl *PropertyDecl = dyn_cast_or_null<ObjCPropertyDecl>(PDecl); + QualType PropertyTy = PropertyDecl->getType(); // readonly and readwrite/assign/retain/copy conflict. if ((Attributes & ObjCDeclSpec::DQ_PR_readonly) && @@ -1010,7 +1013,8 @@ void Sema::CheckObjCPropertyAttributes(QualType PropertyTy, if ((Attributes & (ObjCDeclSpec::DQ_PR_copy | ObjCDeclSpec::DQ_PR_retain)) && !PropertyTy->isObjCObjectPointerType() && !PropertyTy->isBlockPointerType() && - !Context.isObjCNSObjectType(PropertyTy)) { + !Context.isObjCNSObjectType(PropertyTy) && + !PropertyDecl->getAttr<ObjCNSObjectAttr>()) { Diag(Loc, diag::err_objc_property_requires_object) << (Attributes & ObjCDeclSpec::DQ_PR_copy ? "copy" : "retain"); Attributes &= ~(ObjCDeclSpec::DQ_PR_copy | ObjCDeclSpec::DQ_PR_retain); diff --git a/test/SemaObjC/nsobject-attribute.m b/test/SemaObjC/nsobject-attribute.m index fdf9e358ee..13a4929995 100644 --- a/test/SemaObjC/nsobject-attribute.m +++ b/test/SemaObjC/nsobject-attribute.m @@ -7,11 +7,16 @@ static CGColorRef tmp = 0; typedef struct S1 __attribute__ ((NSObject)) CGColorRef1; // expected-error {{__attribute ((NSObject)) is for pointer types only}} typedef void * __attribute__ ((NSObject)) CGColorRef2; // expected-error {{__attribute ((NSObject)) is for pointer types only}} + @interface HandTested { @public CGColorRef x; } + @property(copy) CGColorRef x; +// rdar: // 7809460 +typedef struct CGColor *CGColorRefNoNSObject; +@property (nonatomic, retain) __attribute__((NSObject)) CGColorRefNoNSObject color; @end void setProperty(id self, id value) { @@ -24,6 +29,7 @@ id getProperty(id self) { @implementation HandTested @synthesize x=x; +@dynamic color; @end int main(int argc, char *argv[]) { |