[cfe-commits] r100577 - in /cfe/trunk: lib/Parse/ParseObjc.cpp lib/Sema/SemaDecl.cpp test/SemaObjC/ivar-in-class-extension-error.m test/SemaObjC/ivar-in-class-extension.m
Fariborz Jahanian
fjahanian at apple.com
Tue Apr 6 15:43:48 PDT 2010
Author: fjahanian
Date: Tue Apr 6 17:43:48 2010
New Revision: 100577
URL: http://llvm.org/viewvc/llvm-project?rev=100577&view=rev
Log:
Patch to not build ivar ASTs when they are ilegally
declared in categories.
Modified:
cfe/trunk/lib/Parse/ParseObjc.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaObjC/ivar-in-class-extension-error.m
cfe/trunk/test/SemaObjC/ivar-in-class-extension.m
Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=100577&r1=100576&r2=100577&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Tue Apr 6 17:43:48 2010
@@ -1053,7 +1053,8 @@
= 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);
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=100577&r1=100576&r2=100577&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Apr 6 17:43:48 2010
@@ -5747,8 +5747,16 @@
// 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 @@
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]);
}
}
}
Modified: cfe/trunk/test/SemaObjC/ivar-in-class-extension-error.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/ivar-in-class-extension-error.m?rev=100577&r1=100576&r2=100577&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/ivar-in-class-extension-error.m (original)
+++ cfe/trunk/test/SemaObjC/ivar-in-class-extension-error.m Tue Apr 6 17:43:48 2010
@@ -3,13 +3,13 @@
@interface A @end
- at interface A () { // expected-error {{ivars may not be placed in class extension}}
- int _p0;
+ at interface A () {
+ int _p0; // expected-error {{ivars may not be placed in class extension}}
}
@property int p0;
@end
- at interface A(CAT) { // expected-error {{ivars may not be placed in categories}}
- int _p1;
+ at interface A(CAT) {
+ int _p1; // expected-error {{ivars may not be placed in categories}}
}
@end
Modified: cfe/trunk/test/SemaObjC/ivar-in-class-extension.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/ivar-in-class-extension.m?rev=100577&r1=100576&r2=100577&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/ivar-in-class-extension.m (original)
+++ cfe/trunk/test/SemaObjC/ivar-in-class-extension.m Tue Apr 6 17:43:48 2010
@@ -31,12 +31,12 @@
@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
More information about the cfe-commits
mailing list