[cfe-commits] r157780 - in /cfe/trunk: lib/Sema/SemaDeclAttr.cpp test/SemaObjC/nsobject-attribute.m

Fariborz Jahanian fjahanian at apple.com
Thu May 31 16:18:33 PDT 2012


Author: fjahanian
Date: Thu May 31 18:18:32 2012
New Revision: 157780

URL: http://llvm.org/viewvc/llvm-project?rev=157780&view=rev
Log:
objc: properties of NSObject attribute must
have correct pointer type or issue error,
instead of crashing in IRGen. // rdar:// 11569860

Modified:
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
    cfe/trunk/test/SemaObjC/nsobject-attribute.m

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=157780&r1=157779&r2=157780&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Thu May 31 18:18:32 2012
@@ -2085,7 +2085,15 @@
       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));

Modified: cfe/trunk/test/SemaObjC/nsobject-attribute.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/nsobject-attribute.m?rev=157780&r1=157779&r2=157780&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/nsobject-attribute.m (original)
+++ cfe/trunk/test/SemaObjC/nsobject-attribute.m Thu May 31 18:18:32 2012
@@ -46,9 +46,19 @@
    __attribute__((NSObject)) void * color; // expected-warning {{__attribute ((NSObject)) may be put on a typedef only, attribute is ignored}}
 }
   // <rdar://problem/10930507>
- at property (nonatomic, retain) __attribute__((NSObject)) void * color; // // no-warning
+ at 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
+ at interface A { int i; }
+ at 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}}
+ at end
+
+ at implementation A
+ at synthesize i;
+ at end
+





More information about the cfe-commits mailing list