Fix <rdar://problem/6329769> [sema] crash on duplication definition of interface with protocols.

As soon as we detect duplicate interfaces, discontinue further semantic checks (returning the original interface).

This is now consistent with how we handle protocols (and less error prone in general).



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59541 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp
index 8eeb2d3..49b9909 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -75,9 +75,12 @@
   ObjCInterfaceDecl* IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl);
   if (IDecl) {
     // Class already seen. Is it a forward declaration?
-    if (!IDecl->isForwardDecl())
+    if (!IDecl->isForwardDecl()) {
       Diag(AtInterfaceLoc, diag::err_duplicate_class_def, IDecl->getName());
-    else {
+      // Return the previous class interface.
+      // FIXME: don't leak the objects passed in!
+      return IDecl;
+    } else {
       IDecl->setLocation(AtInterfaceLoc);
       IDecl->setForwardDecl(false);
     }
@@ -119,7 +122,7 @@
     IDecl->setLocEnd(ClassLoc);
   }
   
-  /// Check then save referenced protocols
+  /// Check then save referenced protocols.
   if (NumProtoRefs) {
     IDecl->addReferencedProtocols((ObjCProtocolDecl**)ProtoRefs, NumProtoRefs);
     IDecl->setLocEnd(EndProtoLoc);