Fix chaining of ObjCInterfaceDecl redeclarations

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146722 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp
index 02a83e5..4f87db4 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -366,11 +366,11 @@
   }
 
   // Create a declaration to describe this @interface.
+  ObjCInterfaceDecl* PrevIDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl);
   ObjCInterfaceDecl *IDecl
     = ObjCInterfaceDecl::Create(Context, CurContext, AtInterfaceLoc, ClassName,
-                                ClassLoc);
+                                PrevIDecl, ClassLoc);
   
-  ObjCInterfaceDecl* PrevIDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl);
   if (PrevIDecl) {
     // Class already seen. Was it a definition?
     if (ObjCInterfaceDecl *Def = PrevIDecl->getDefinition()) {
@@ -379,9 +379,6 @@
       Diag(Def->getLocation(), diag::note_previous_definition);
       IDecl->setInvalidDecl();
     }
-
-    // Link to the previous declaration.
-    IDecl->setPreviousDeclaration(PrevIDecl);
   }
   
   if (AttrList)
@@ -870,9 +867,8 @@
     Diag(ClassLoc, diag::err_redefinition_different_kind) << ClassName;
     Diag(PrevDecl->getLocation(), diag::note_previous_definition);
   } else if ((IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl))) {
-    if (RequireCompleteType(ClassLoc, Context.getObjCInterfaceType(IDecl),
-                            diag::warn_undef_interface))
-      IDecl = 0;
+    RequireCompleteType(ClassLoc, Context.getObjCInterfaceType(IDecl),
+                        diag::warn_undef_interface);
   } else {
     // We did not find anything with the name ClassName; try to correct for 
     // typos in the class name.
@@ -928,7 +924,8 @@
     // FIXME: Do we support attributes on the @implementation? If so we should
     // copy them over.
     IDecl = ObjCInterfaceDecl::Create(Context, CurContext, AtClassImplLoc,
-                                      ClassName, ClassLoc, true);
+                                      ClassName, /*PrevDecl=*/0, ClassLoc, 
+                                      true);
     IDecl->startDefinition();
     if (SDecl) {
       IDecl->setSuperClass(SDecl);
@@ -1774,16 +1771,13 @@
     }
     
     // Create a declaration to describe this forward declaration.
+    ObjCInterfaceDecl *PrevIDecl
+      = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl);
     ObjCInterfaceDecl *IDecl
       = ObjCInterfaceDecl::Create(Context, CurContext, AtClassLoc,
-                                  IdentList[i], IdentLocs[i], true);
+                                  IdentList[i], PrevIDecl, IdentLocs[i], true);
     IDecl->setAtEndRange(IdentLocs[i]);
     
-    // If there was a previous declaration, link to it.
-    if (ObjCInterfaceDecl *PrevIDecl
-        = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl))
-      IDecl->setPreviousDeclaration(PrevIDecl);
-
     // Create the forward declaration. Note that we intentionally do this 
     // before we add the ObjCInterfaceDecl we just created, so that the
     // rewriter sees the ObjCClassDecl first.