summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDeclObjC.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2010-02-23 19:39:46 +0000
committerTed Kremenek <kremenek@apple.com>2010-02-23 19:39:46 +0000
commit514ff70d04edec8a9a30e5ea73c1ca02e74a8fc9 (patch)
tree995535ffa2f4791d0e22f8f4598bda981a7672db /clang/lib/Sema/SemaDeclObjC.cpp
parentd09b921b7da587441a536f0aba34d0d14c7cf22b (diff)
downloadbcm5719-llvm-514ff70d04edec8a9a30e5ea73c1ca02e74a8fc9.tar.gz
bcm5719-llvm-514ff70d04edec8a9a30e5ea73c1ca02e74a8fc9.zip
Fix another crash on invalid code. In this case, handle ObjC categories (with no names)
that refer to an undefined class. llvm-svn: 96976
Diffstat (limited to 'clang/lib/Sema/SemaDeclObjC.cpp')
-rw-r--r--clang/lib/Sema/SemaDeclObjC.cpp29
1 files changed, 19 insertions, 10 deletions
diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp
index e40e8fedc07..925c0db4e40 100644
--- a/clang/lib/Sema/SemaDeclObjC.cpp
+++ b/clang/lib/Sema/SemaDeclObjC.cpp
@@ -599,22 +599,31 @@ ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc,
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)
OpenPOWER on IntegriCloud