]> granicus.if.org Git - clang/commitdiff
objc: properties of NSObject attribute must
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 31 May 2012 23:18:32 +0000 (23:18 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 31 May 2012 23:18:32 +0000 (23:18 +0000)
have correct pointer type or issue error,
instead of crashing in IRGen. // rdar:// 11569860

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@157780 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclAttr.cpp
test/SemaObjC/nsobject-attribute.m

index 4175ec1a26ece5e2ec99e6dcd9a28883f4ba0391..c98d2bb9f4de2e06836e185e432520ef05700745 100644 (file)
@@ -2085,7 +2085,15 @@ static void handleObjCNSObject(Sema &S, Decl *D, const AttributeList &Attr) {
       return;
     }
   }
-  else if (!isa<ObjCPropertyDecl>(D)) {
+  else if (ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(D)) {
+    QualType T = PD->getType();
+    if (!T->isPointerType() ||
+        !T->getAs<PointerType>()->getPointeeType()->isRecordType()) {
+      S.Diag(PD->getLocation(), diag::err_nsobject_attribute);
+      return;
+    }
+  }
+  else {
     // It is okay to include this attribute on properties, e.g.:
     //
     //  @property (retain, nonatomic) struct Bork *Q __attribute__((NSObject));
index f41df8932887e9d7a7f3a2fa20506b6ccfc3e985..e3f28740dc8f4827c267f335f47571c238b1f8f5 100644 (file)
@@ -46,9 +46,19 @@ int main(int argc, char *argv[]) {
    __attribute__((NSObject)) void * color; // expected-warning {{__attribute ((NSObject)) may be put on a typedef only, attribute is ignored}}
 }
   // <rdar://problem/10930507>
-@property (nonatomic, retain) __attribute__((NSObject)) void * color; // // no-warning
+@property (nonatomic, retain) __attribute__((NSObject)) CGColorRefNoNSObject color; // // no-warning
 @end
 void test_10453342() {
     char* __attribute__((NSObject)) string2 = 0; // expected-warning {{__attribute ((NSObject)) may be put on a typedef only, attribute is ignored}}
 }
 
+// rdar://11569860
+@interface A { int i; }
+@property(retain) __attribute__((NSObject)) int i; // expected-error {{__attribute ((NSObject)) is for pointer types only}} \
+                                                  // expected-error {{property with 'retain (or strong)' attribute must be of object type}}
+@end
+
+@implementation A
+@synthesize i;
+@end
+