HandleDeclarator() returns NULL for semantic disasters. Deal with it
when we're in an Objective-C container context. Fixes
<rdar://problem/11286701>.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@155836 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 09d9d34..6b18c98 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -3233,7 +3233,7 @@
   Decl *Dcl = HandleDeclarator(S, D, MultiTemplateParamsArg(*this));
 
   if (OriginalLexicalContext && OriginalLexicalContext->isObjCContainer() &&
-      Dcl->getDeclContext()->isFileContext())
+      Dcl && Dcl->getDeclContext()->isFileContext())
     Dcl->setTopLevelDeclInObjCContainer();
 
   return Dcl;
diff --git a/test/SemaObjCXX/crash.mm b/test/SemaObjCXX/crash.mm
new file mode 100644
index 0000000..345f72e
--- /dev/null
+++ b/test/SemaObjCXX/crash.mm
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify 
+
+// <rdar://problem/11286701>
+namespace std {
+  template<typename T, typename U> class pair;
+}
+
+@interface NSObject
+@end
+
+@interface Test : NSObject
+@end
+
+@implementation Test
+
+struct EvilStruct {
+} // note the missing semicolon
+
+  typedef std::pair<int, int> IntegerPair; // expected-error{{typedef declarator cannot be qualified}} \
+// expected-error{{typedef name must be an identifier}} \
+// expected-error{{expected ';' after top level declarator}}
+
+@end