Fix crash on invalid code.  I've tried to produce a reduced test case, but when I do the specific crash is hidden.  Fixes <rdar://problem/11063594>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152968 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExprMember.cpp b/lib/Sema/SemaExprMember.cpp
index 180c1aa..4155fdb 100644
--- a/lib/Sema/SemaExprMember.cpp
+++ b/lib/Sema/SemaExprMember.cpp
@@ -1127,7 +1127,7 @@
                               << BaseExpr.get()->getSourceRange()))
       return ExprError();
     
-    ObjCInterfaceDecl *ClassDeclared;
+    ObjCInterfaceDecl *ClassDeclared = 0;
     ObjCIvarDecl *IV = IDecl->lookupInstanceVariable(Member, ClassDeclared);
 
     if (!IV) {
@@ -1145,6 +1145,13 @@
                                           IV->getNameAsString());
         Diag(IV->getLocation(), diag::note_previous_decl)
           << IV->getDeclName();
+        
+        // Figure out the class that declares the ivar.
+        assert(!ClassDeclared);
+        Decl *D = cast<Decl>(IV->getDeclContext());
+        if (ObjCCategoryDecl *CAT = dyn_cast<ObjCCategoryDecl>(D))
+          D = CAT->getClassInterface();
+        ClassDeclared = cast<ObjCInterfaceDecl>(D);
       } else {
         if (IsArrow && IDecl->FindPropertyDeclaration(Member)) {
           Diag(MemberLoc, 
@@ -1160,6 +1167,8 @@
         return ExprError();
       }
     }
+    
+    assert(ClassDeclared);
 
     // If the decl being referenced had an error, return an error for this
     // sub-expr without emitting another error, in order to avoid cascading