Patch to not build ivar ASTs when they are ilegally

declared in categories.

llvm-svn: 100577
This commit is contained in:
Fariborz Jahanian 2010-04-06 22:43:48 +00:00
parent 2351cb9139
commit 6a0a2e0ccc
4 changed files with 26 additions and 19 deletions

View File

@ -1053,7 +1053,8 @@ void Parser::ParseObjCClassInstanceVariables(DeclPtrTy interfaceDecl,
= P.Actions.ActOnIvar(P.CurScope,
FD.D.getDeclSpec().getSourceRange().getBegin(),
IDecl, FD.D, FD.BitfieldSize, visibility);
AllIvarDecls.push_back(Field);
if (Field)
AllIvarDecls.push_back(Field);
return Field;
}
} Callback(*this, interfaceDecl, visibility, AllIvarDecls);

View File

@ -5747,8 +5747,16 @@ Sema::DeclPtrTy Sema::ActOnIvar(Scope *S,
// Case of ivar declared in an implementation. Context is that of its class.
EnclosingContext = IMPDecl->getClassInterface();
assert(EnclosingContext && "Implementation has no class interface!");
} else
} else {
if (ObjCCategoryDecl *CDecl =
dyn_cast<ObjCCategoryDecl>(EnclosingDecl)) {
if (!LangOpts.ObjCNonFragileABI2 || !CDecl->IsClassExtension()) {
Diag(Loc, diag::err_misplaced_ivar) << CDecl->IsClassExtension();
return DeclPtrTy();
}
}
EnclosingContext = EnclosingDecl;
}
// Construct the decl.
ObjCIvarDecl *NewID = ObjCIvarDecl::Create(Context,
@ -5926,16 +5934,14 @@ void Sema::ActOnFields(Scope* S,
CheckImplementationIvars(IMPDecl, ClsFields, RecFields.size(), RBrac);
} else if (ObjCCategoryDecl *CDecl =
dyn_cast<ObjCCategoryDecl>(EnclosingDecl)) {
if (!LangOpts.ObjCNonFragileABI2 || !CDecl->IsClassExtension())
Diag(LBrac, diag::err_misplaced_ivar) << CDecl->IsClassExtension();
else {
// FIXME. Class extension does not have a LocEnd field.
// CDecl->setLocEnd(RBrac);
// Add ivar's to class extension's DeclContext.
for (unsigned i = 0, e = RecFields.size(); i != e; ++i) {
ClsFields[i]->setLexicalDeclContext(CDecl);
CDecl->addDecl(ClsFields[i]);
}
// case of ivars in class extension; all other cases have been
// reported as errors elsewhere.
// FIXME. Class extension does not have a LocEnd field.
// CDecl->setLocEnd(RBrac);
// Add ivar's to class extension's DeclContext.
for (unsigned i = 0, e = RecFields.size(); i != e; ++i) {
ClsFields[i]->setLexicalDeclContext(CDecl);
CDecl->addDecl(ClsFields[i]);
}
}
}

View File

@ -3,13 +3,13 @@
@interface A @end
@interface A () { // expected-error {{ivars may not be placed in class extension}}
int _p0;
@interface A () {
int _p0; // expected-error {{ivars may not be placed in class extension}}
}
@property int p0;
@end
@interface A(CAT) { // expected-error {{ivars may not be placed in categories}}
int _p1;
@interface A(CAT) {
int _p1; // expected-error {{ivars may not be placed in categories}}
}
@end

View File

@ -31,12 +31,12 @@ int fn3(SomeClass *obj) {
@end
@interface SomeClass (Category)
{ // expected-error {{ivars may not be placed in categories}}
int categoryIvar;
{
int categoryIvar; // expected-error {{ivars may not be placed in categories}}
}
@end
@interface SomeClass (Category1)
{ // expected-error {{ivars may not be placed in categories}}
{
}
@end