Recover from user typo not having proper @interface decl and a bad foreach decl.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45839 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Sema/SemaDeclObjC.cpp b/Sema/SemaDeclObjC.cpp
index 89b7611..b2e7b79 100644
--- a/Sema/SemaDeclObjC.cpp
+++ b/Sema/SemaDeclObjC.cpp
@@ -43,9 +43,14 @@
PI.IdentLoc = SourceLocation(); // synthesized vars have a null location.
PI.InvalidType = false;
if (MDecl->isInstance()) {
- QualType selfTy = Context.getObjCInterfaceType(MDecl->getClassInterface());
- selfTy = Context.getPointerType(selfTy);
- PI.TypeInfo = selfTy.getAsOpaquePtr();
+ ObjCInterfaceDecl *OID = MDecl->getClassInterface();
+ // There may be no interface context due to error in declaration of the
+ // interface (which has been reported). Recover gracefully
+ if (OID) {
+ QualType selfTy = Context.getObjCInterfaceType(OID);
+ selfTy = Context.getPointerType(selfTy);
+ PI.TypeInfo = selfTy.getAsOpaquePtr();
+ }
} else
PI.TypeInfo = Context.getObjCIdType().getAsOpaquePtr();
CurMethodDecl->setSelfDecl(ActOnParamDeclarator(PI, FnBodyScope));