From da3253d8a97981257185c89ced71ce137278b121 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 20 Oct 2008 06:33:53 +0000 Subject: [PATCH] fix a crash on unnamed properties like: @property (readonly) int : 4; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57805 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticKinds.def | 2 ++ lib/Parse/ParseObjc.cpp | 20 +++++++++++++------- test/SemaObjC/property-9.m | 12 ++++++++++++ 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def index 3ec0058555..09eb5d98e1 100644 --- a/include/clang/Basic/DiagnosticKinds.def +++ b/include/clang/Basic/DiagnosticKinds.def @@ -418,6 +418,8 @@ DIAG(err_objc_illegal_interface_qual, ERROR, "illegal interface qualifier") DIAG(err_objc_expected_equal, ERROR, "setter/getter expects '=' followed by name") +DIAG(err_objc_property_requires_field_name, ERROR, + "@property requires fields to be named") DIAG(err_objc_expected_property_attr, ERROR, "unknown property attribute detected") DIAG(err_objc_unexpected_attr, ERROR, diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp index cc5a74d7c6..80de1b0ef3 100644 --- a/lib/Parse/ParseObjc.cpp +++ b/lib/Parse/ParseObjc.cpp @@ -316,21 +316,27 @@ void Parser::ParseObjCInterfaceDeclList(DeclTy *interfaceDecl, // Convert them all to property declarations. for (unsigned i = 0, e = FieldDeclarators.size(); i != e; ++i) { FieldDeclarator &FD = FieldDeclarators[i]; + if (FD.D.getIdentifier() == 0) { + Diag(AtLoc, diag::err_objc_property_requires_field_name, + FD.D.getSourceRange()); + continue; + } + // Install the property declarator into interfaceDecl. + IdentifierInfo *SelName = + OCDS.getGetterName() ? OCDS.getGetterName() : FD.D.getIdentifier(); + Selector GetterSel = - PP.getSelectorTable().getNullarySelector(OCDS.getGetterName() - ? OCDS.getGetterName() - : FD.D.getIdentifier()); + PP.getSelectorTable().getNullarySelector(SelName); IdentifierInfo *SetterName = OCDS.getSetterName(); if (!SetterName) SetterName = constructSetterName(PP.getIdentifierTable(), FD.D.getIdentifier()); Selector SetterSel = PP.getSelectorTable().getUnarySelector(SetterName); - DeclTy *Property = Actions.ActOnProperty(CurScope, - AtLoc, FD, OCDS, - GetterSel, SetterSel, - MethodImplKind); + DeclTy *Property = Actions.ActOnProperty(CurScope, AtLoc, FD, OCDS, + GetterSel, SetterSel, + MethodImplKind); allProperties.push_back(Property); } break; diff --git a/test/SemaObjC/property-9.m b/test/SemaObjC/property-9.m index b83291aaca..ed6c5342e8 100644 --- a/test/SemaObjC/property-9.m +++ b/test/SemaObjC/property-9.m @@ -36,3 +36,15 @@ typedef signed char BOOL; @implementation MyClass @synthesize myIvar = _myIvar; @end + + +@interface BadPropClass +{ +} + +@property (readonly) int; // expected-warning {{declaration does not declare anything}} +@property (readonly) ; // expected-error {{type name requires a specifier or qualifier}} \ + expected-warning {{declaration does not declare anything}} +@property (readonly) int : 4; // expected-error {{property requires fields to be named}} + +@end -- 2.40.0