[cfe-commits] r96976 - in /cfe/trunk: lib/Sema/SemaDeclObjC.cpp test/SemaObjC/category-1.m
Ted Kremenek
kremenek at apple.com
Tue Feb 23 11:39:46 PST 2010
Author: kremenek
Date: Tue Feb 23 13:39:46 2010
New Revision: 96976
URL: http://llvm.org/viewvc/llvm-project?rev=96976&view=rev
Log:
Fix another crash on invalid code. In this case, handle ObjC categories (with no names)
that refer to an undefined class.
Modified:
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/test/SemaObjC/category-1.m
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=96976&r1=96975&r2=96976&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Tue Feb 23 13:39:46 2010
@@ -599,22 +599,31 @@
SourceLocation EndProtoLoc) {
ObjCCategoryDecl *CDecl = 0;
ObjCInterfaceDecl *IDecl = getObjCInterfaceDecl(ClassName, ClassLoc);
- if (!CategoryName)
+
+ /// Check that class of this category is already completely declared.
+ if (!IDecl || IDecl->isForwardDecl()) {
+ // Create an invalid ObjCCategoryDecl to serve as context for
+ // the enclosing method declarations. We mark the decl invalid
+ // to make it clear that this isn't a valid AST.
+ CDecl = ObjCCategoryDecl::Create(Context, CurContext, AtInterfaceLoc,
+ ClassLoc, CategoryLoc, CategoryName);
+ CDecl->setInvalidDecl();
+ Diag(ClassLoc, diag::err_undef_interface) << ClassName;
+ return DeclPtrTy::make(CDecl);
+ }
+
+ if (!CategoryName) {
// Class extensions require a special treatment. Use an existing one.
+ // Note that 'getClassExtension()' can return NULL.
CDecl = IDecl->getClassExtension();
+ }
+
if (!CDecl) {
- CDecl = ObjCCategoryDecl::Create(Context, CurContext, AtInterfaceLoc, ClassLoc,
- CategoryLoc, CategoryName);
+ CDecl = ObjCCategoryDecl::Create(Context, CurContext, AtInterfaceLoc,
+ ClassLoc, CategoryLoc, CategoryName);
// FIXME: PushOnScopeChains?
CurContext->addDecl(CDecl);
- /// Check that class of this category is already completely declared.
- if (!IDecl || IDecl->isForwardDecl()) {
- CDecl->setInvalidDecl();
- Diag(ClassLoc, diag::err_undef_interface) << ClassName;
- return DeclPtrTy::make(CDecl);
- }
-
CDecl->setClassInterface(IDecl);
// Insert first use of class extension to the list of class's categories.
if (!CategoryName)
Modified: cfe/trunk/test/SemaObjC/category-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/category-1.m?rev=96976&r1=96975&r2=96976&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/category-1.m (original)
+++ cfe/trunk/test/SemaObjC/category-1.m Tue Feb 23 13:39:46 2010
@@ -73,3 +73,7 @@
@implementation MultipleCat_I // expected-warning {{incomplete implementation}}, expected-warning {{method definition for 'im0' not found}}
@end
+
+// <rdar://problem/7680391> - Handle nameless categories with no name that refer
+// to an undefined class
+ at interface RDar7680391 () @end // expected-error{{cannot find interface declaration}}
More information about the cfe-commits
mailing list