In the override search for Objective-C methods, protect against ASTs that have NULL...
authorDouglas Gregor <dgregor@apple.com>
Thu, 17 May 2012 22:39:14 +0000 (22:39 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 17 May 2012 22:39:14 +0000 (22:39 +0000)
llvm-svn: 157021

clang/lib/Sema/SemaDeclObjC.cpp
clang/test/SemaObjC/category-1.m

index 02430e6..10bc1c2 100644 (file)
@@ -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);
   }
 
 
index f842278..a7e6965 100644 (file)
 @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