aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2012-05-17 22:39:14 +0000
committerDouglas Gregor <dgregor@apple.com>2012-05-17 22:39:14 +0000
commitdd87224ad67b79e9c48dd4a06779b353aa633cbb (patch)
tree9ed5fa18f936552de78b0e9256d160bd514509dc
parent01428ab7e6358afbd46693d7c8b1b08b0eda4978 (diff)
In the override search for Objective-C methods, protect against ASTs that have NULL interfaces behind a category, which can happen in invalid code. Fixes <rdar://problem/11478173>, a recent regression
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@157021 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaDeclObjC.cpp13
-rw-r--r--test/SemaObjC/category-1.m9
2 files changed, 17 insertions, 5 deletions
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp
index 02430e6da5..10bc1c27f0 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -2520,7 +2520,8 @@ public:
// interface and each other.
if (ObjCCategoryDecl *Category = dyn_cast<ObjCCategoryDecl>(container)) {
searchFromContainer(container);
- searchFromContainer(Category->getClassInterface());
+ if (ObjCInterfaceDecl *Interface = Category->getClassInterface())
+ searchFromContainer(Interface);
} else {
searchFromContainer(container);
}
@@ -2569,11 +2570,12 @@ private:
// declaration.
if (ObjCCategoryDecl *category = impl->getCategoryDecl()) {
search(category);
- search(category->getClassInterface());
+ if (ObjCInterfaceDecl *Interface = category->getClassInterface())
+ search(Interface);
// Otherwise it overrides declarations from the class.
- } else {
- search(impl->getClassInterface());
+ } else if (ObjCInterfaceDecl *Interface = impl->getClassInterface()) {
+ search(Interface);
}
}
@@ -2598,7 +2600,8 @@ private:
void searchFrom(ObjCImplementationDecl *impl) {
// A method in a class implementation overrides declarations from
// the class interface.
- search(impl->getClassInterface());
+ if (ObjCInterfaceDecl *Interface = impl->getClassInterface())
+ search(Interface);
}
diff --git a/test/SemaObjC/category-1.m b/test/SemaObjC/category-1.m
index f8422782d7..a7e69651ad 100644
--- a/test/SemaObjC/category-1.m
+++ b/test/SemaObjC/category-1.m
@@ -99,3 +99,12 @@
@class I; // expected-note {{forward declaration}}
@implementation I(cat) // expected-error{{cannot find interface declaration}}
@end
+
+// <rdar://problem/11478173>
+@interface Unrelated
+- foo;
+@end
+
+@interface Blah (Blarg) // expected-error{{cannot find interface declaration for 'Blah'}}
+- foo;
+@end