aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-01-09 01:04:21 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-01-09 01:04:21 +0000
commit84efc04f41b9760f339717834373db19a74c14fe (patch)
treed13c4ec45c146c21ab86482671cb6ee780f3dc8d
parent9066af807a4e54558219f42111f1925c49d9af75 (diff)
Fix crash on null deference when searching for readwrite properties in
categories. - Also, simplify nesting via early return. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61968 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/AST/DeclObjC.cpp28
-rw-r--r--test/SemaObjC/property-category-1.m17
2 files changed, 32 insertions, 13 deletions
diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp
index 194544f9fa..cf3bd0abea 100644
--- a/lib/AST/DeclObjC.cpp
+++ b/lib/AST/DeclObjC.cpp
@@ -252,24 +252,26 @@ void ObjCMethodDecl::setMethodParams(ParmVarDecl **NewParamInfo,
}
}
-/// 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
diff --git a/test/SemaObjC/property-category-1.m b/test/SemaObjC/property-category-1.m
index 32e14f00c1..926f964202 100644
--- a/test/SemaObjC/property-category-1.m
+++ b/test/SemaObjC/property-category-1.m
@@ -33,3 +33,20 @@ int main(int argc, char **argv) {
return test.object - 12345 + test.Anotherobject - 200;
}
+///
+
+@interface I0
+@property(readonly) int p0;
+@end
+
+@interface I0 (Cat0)
+@end
+
+@interface I0 (Cat1)
+@end
+
+@implementation I0
+- (void) foo {
+ self.p0 = 0; // expected-error {{assigning to property with 'readonly' attribute not allowed}}
+}
+@end