[cfe-commits] r61968 - in /cfe/trunk: lib/AST/DeclObjC.cpp test/SemaObjC/property-category-1.m

Daniel Dunbar daniel at zuster.org
Thu Jan 8 17:04:22 PST 2009


Author: ddunbar
Date: Thu Jan  8 19:04:21 2009
New Revision: 61968

URL: http://llvm.org/viewvc/llvm-project?rev=61968&view=rev
Log:
Fix crash on null deference when searching for readwrite properties in
categories.
 - Also, simplify nesting via early return.

Modified:
    cfe/trunk/lib/AST/DeclObjC.cpp
    cfe/trunk/test/SemaObjC/property-category-1.m

Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=61968&r1=61967&r2=61968&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Thu Jan  8 19:04:21 2009
@@ -252,24 +252,26 @@
   }
 }
 
-/// isPropertyReadonly - Return true if property is a readonly, by seaching
+/// isPropertyReadonly - Return true if property is readonly, by searching
 /// for the property in the class and in its categories.
 ///
 bool ObjCInterfaceDecl::isPropertyReadonly(ObjCPropertyDecl *PDecl) const
 {
-  if (PDecl->isReadOnly()) {
-    // Main class has the property as 'readyonly'. Must search
-    // through the category list to see if the property's 
-    // attribute has been over-ridden to 'readwrite'.
-    for (ObjCCategoryDecl *Category = getCategoryList();
-         Category; Category = Category->getNextClassCategory()) {
-      PDecl= Category->FindPropertyDeclaration(PDecl->getIdentifier());
-      if (PDecl && !PDecl->isReadOnly())
-        return false;
-    }
-    return true;
+  if (!PDecl->isReadOnly())
+    return false;
+
+  // Main class has the property as 'readonly'. Must search
+  // through the category list to see if the property's 
+  // attribute has been over-ridden to 'readwrite'.
+  for (ObjCCategoryDecl *Category = getCategoryList();
+       Category; Category = Category->getNextClassCategory()) {
+    ObjCPropertyDecl *P = 
+      Category->FindPropertyDeclaration(PDecl->getIdentifier());
+    if (P && !P->isReadOnly())
+      return false;
   }
-  return false;  
+
+  return true;
 }
 
 /// FindPropertyDeclaration - Finds declaration of the property given its name

Modified: cfe/trunk/test/SemaObjC/property-category-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/property-category-1.m?rev=61968&r1=61967&r2=61968&view=diff

==============================================================================
--- cfe/trunk/test/SemaObjC/property-category-1.m (original)
+++ cfe/trunk/test/SemaObjC/property-category-1.m Thu Jan  8 19:04:21 2009
@@ -33,3 +33,20 @@
     return test.object - 12345 + test.Anotherobject - 200;
 }
 
+///
+
+ at interface I0
+ at property(readonly) int p0;
+ at end 
+
+ at interface I0 (Cat0)
+ at end 
+
+ at interface I0 (Cat1)
+ at end 
+  
+ at implementation I0
+- (void) foo {
+  self.p0 = 0; // expected-error {{assigning to property with 'readonly' attribute not allowed}}
+}
+ at end





More information about the cfe-commits mailing list