Fix the insertion of label declarations into the identifier chain in
the case where we only have a single identifier with that name in the
chain. Fixes PR9463 for real this time.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@128208 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/IdentifierResolver.cpp b/lib/Sema/IdentifierResolver.cpp
index d520a6e..95420a3 100644
--- a/lib/Sema/IdentifierResolver.cpp
+++ b/lib/Sema/IdentifierResolver.cpp
@@ -172,13 +172,28 @@
   DeclarationName Name = D->getDeclName();
   void *Ptr = Name.getFETokenInfo<void>();
   
-  if (Pos == iterator() || isDeclPtr(Ptr)) {
-    // Simple case: insert at the end of the list (which is the
-    // end of the stored vector).
+  if (!Ptr) {
     AddDecl(D);
     return;
   }
 
+  if (isDeclPtr(Ptr)) {
+    // We only have a single declaration: insert before or after it,
+    // as appropriate.
+    if (Pos == iterator()) {
+      // Add the new declaration before the existing declaration.
+      NamedDecl *PrevD = static_cast<NamedDecl*>(Ptr);
+      RemoveDecl(PrevD);
+      AddDecl(D);
+      AddDecl(PrevD);
+    } else {
+      // Add new declaration after the existing declaration.
+      AddDecl(D);
+    }
+
+    return;
+  }
+
   if (IdentifierInfo *II = Name.getAsIdentifierInfo())
     II->setIsFromAST(false);