diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h
index 6d0a7f1..eba9355 100644
--- a/include/clang/AST/Decl.h
+++ b/include/clang/AST/Decl.h
@@ -770,6 +770,7 @@ protected:
   virtual VarDecl *getMostRecentDeclImpl() {
     return getMostRecentDecl();
   }
+  virtual VarDecl *getFirstDeclImpl() { return getFirstDeclaration(); }
 
 public:
   typedef redeclarable_base::redecl_iterator redecl_iterator;
@@ -1558,6 +1559,7 @@ protected:
   virtual FunctionDecl *getMostRecentDeclImpl() {
     return getMostRecentDecl();
   }
+  virtual FunctionDecl *getFirstDeclImpl() { return getFirstDeclaration(); }
 
 public:
   typedef redeclarable_base::redecl_iterator redecl_iterator;
@@ -3489,10 +3491,12 @@ void Redeclarable<decl_type>::setPreviousDeclaration(decl_type *PrevDecl) {
     // Point to previous. Make sure that this is actually the most recent
     // redeclaration, or we can build invalid chains. If the most recent
     // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
-    First = PrevDecl->getFirstDeclaration();
-    assert(First->RedeclLink.NextIsLatest() && "Expected first");
-    decl_type *MostRecent = First->RedeclLink.getNext();
-    RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
+    decl_type *MostRecent = PrevDecl->getMostRecentDecl();
+    assert(MostRecent->RedeclLink.NextIsFirst() && "Expected last");
+    First = MostRecent->RedeclLink.getNext();
+
+    // MostRecent one will point to this one as latest.
+    MostRecent->RedeclLink = NextDeclLink(static_cast<decl_type*>(this));
 
     // If the declaration was previously visible, a redeclaration of it remains
     // visible even if it wouldn't be visible by itself.
@@ -3500,12 +3504,11 @@ void Redeclarable<decl_type>::setPreviousDeclaration(decl_type *PrevDecl) {
       MostRecent->getIdentifierNamespace() &
       (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
   } else {
-    // Make this first.
+    // Make this the first.
     First = static_cast<decl_type*>(this);
   }
 
-  // First one will point to this one as latest.
-  First->RedeclLink = LatestDeclLink(static_cast<decl_type*>(this));
+  RedeclLink = FirstDeclLink(cast<decl_type>(First));
   assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
          cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
 }
diff --git a/include/clang/AST/DeclBase.h b/include/clang/AST/DeclBase.h
index 1fdb857..5b80214 100644
--- a/include/clang/AST/DeclBase.h
+++ b/include/clang/AST/DeclBase.h
@@ -721,6 +721,8 @@ protected:
   /// \brief Implementation of getPreviousDecl(), to be overridden by any
   /// subclass that has a redeclaration chain.
   virtual Decl *getPreviousDeclImpl() { return 0; }
+
+  virtual Decl *getFirstDeclImpl() { assert(0); return 0; }
   
   /// \brief Implementation of getMostRecentDecl(), to be overridden by any
   /// subclass that has a redeclaration chain.  
@@ -779,6 +781,8 @@ public:
   /// \brief Retrieve the previous declaration that declares the same entity
   /// as this declaration, or NULL if there is no previous declaration.
   Decl *getPreviousDecl() { return getPreviousDeclImpl(); }
+
+  Decl *getFirstDecl() { return getFirstDeclImpl(); }
   
   /// \brief Retrieve the most recent declaration that declares the same entity
   /// as this declaration, or NULL if there is no previous declaration.
@@ -844,11 +848,11 @@ public:
             IdentifierNamespace == IDNS_OrdinaryFriend) &&
            "namespace is not ordinary");
 
-    Decl *Prev = getPreviousDecl();
+    Decl *First = getFirstDecl();
     IdentifierNamespace &= ~IDNS_Ordinary;
 
     IdentifierNamespace |= IDNS_LocalExtern;
-    if (Prev && Prev->getIdentifierNamespace() & IDNS_Ordinary)
+    if (First != this && First->getIdentifierNamespace() & IDNS_Ordinary)
       IdentifierNamespace |= IDNS_Ordinary;
   }
 
diff --git a/include/clang/AST/Redeclarable.h b/include/clang/AST/Redeclarable.h
index fbf8996..92f922f 100644
--- a/include/clang/AST/Redeclarable.h
+++ b/include/clang/AST/Redeclarable.h
@@ -26,47 +26,62 @@ class Redeclarable {
 
 protected:
   class DeclLink {
-    llvm::PointerIntPair<decl_type *, 1, bool> NextAndIsPrevious;
+    llvm::PointerIntPair<decl_type *, 1, bool> NextAndNextIsFirst;
   public:
-    DeclLink(decl_type *D, bool isLatest)
-      : NextAndIsPrevious(D, isLatest) { }
-
-    bool NextIsPrevious() const { return !NextAndIsPrevious.getInt(); }
-    bool NextIsLatest() const { return NextAndIsPrevious.getInt(); }
-    decl_type *getNext() const { return NextAndIsPrevious.getPointer(); }
-    void setNext(decl_type *D) { NextAndIsPrevious.setPointer(D); }
+    DeclLink(decl_type *D, bool isFirst)
+      : NextAndNextIsFirst(D, isFirst) { }
+
+    bool NextIsFirst() const { return NextAndNextIsFirst.getInt(); }
+    decl_type *getNext() const { return NextAndNextIsFirst.getPointer(); }
+    void setNext2(decl_type *D) {
+      NextAndNextIsFirst.setPointer(D);
+      NextAndNextIsFirst.setInt(false);
+    }
+    void setFirst(decl_type *D) {
+      NextAndNextIsFirst.setPointer(D);
+      NextAndNextIsFirst.setInt(true);
+    }
   };
 
-  static DeclLink PreviousDeclLink(decl_type *D) {
+  static DeclLink NextDeclLink(decl_type *D) {
     return DeclLink(D, false);
   }
 
-  static DeclLink LatestDeclLink(decl_type *D) {
+  static DeclLink FirstDeclLink(decl_type *D) {
     return DeclLink(D, true);
   }
 
   /// \brief Points to the next redeclaration in the chain.
   ///
-  /// If NextIsPrevious() is true, this is a link to the previous declaration
-  /// of this same Decl. If NextIsLatest() is true, this is the first
-  /// declaration and Link points to the latest declaration. For example:
+  /// If NextIsFirst() is false, this is a link to the next declaration
+  /// of this same Decl. If NextIsFirst() is true, this is the last
+  /// declaration and Link points to the first declaration. For example:
   ///
-  ///  #1 int f(int x, int y = 1); // <pointer to #3, true>
-  ///  #2 int f(int x = 0, int y); // <pointer to #1, false>
-  ///  #3 int f(int x, int y) { return x + y; } // <pointer to #2, false>
+  ///  #1 int f(int x, int y = 1); // <pointer to #2, false>
+  ///  #2 int f(int x = 0, int y); // <pointer to #3, false>
+  ///  #3 int f(int x, int y) { return x + y; } // <pointer to #1, true>
   ///
   /// If there is only one declaration, it is <pointer to self, true>
   DeclLink RedeclLink;
 
 public:
-  Redeclarable() : RedeclLink(LatestDeclLink(static_cast<decl_type*>(this))) { }
+  Redeclarable() : RedeclLink(FirstDeclLink(static_cast<decl_type*>(this))) { }
 
   /// \brief Return the previous declaration of this declaration or NULL if this
   /// is the first declaration.
   decl_type *getPreviousDecl() {
-    if (RedeclLink.NextIsPrevious())
-      return RedeclLink.getNext();
-    return 0;
+    decl_type *D = static_cast<decl_type*>(this);
+
+    decl_type *Next = D;
+    decl_type *Cur;
+    do {
+      Cur = Next;
+      Next = Cur->RedeclLink.getNext();
+    } while (Next != D);
+
+    if (Cur->RedeclLink.NextIsFirst())
+      return 0;
+    return Cur;
   }
   const decl_type *getPreviousDecl() const {
     return const_cast<decl_type *>(
@@ -76,36 +91,48 @@ public:
   /// \brief Return the first declaration of this declaration or itself if this
   /// is the only declaration.
   decl_type *getFirstDeclaration() {
-    decl_type *D = static_cast<decl_type*>(this);
-    while (D->getPreviousDecl())
-      D = D->getPreviousDecl();
-    return D;
+    decl_type *MostRecent = getMostRecentDecl();
+    return MostRecent->RedeclLink.getNext();
   }
 
   /// \brief Return the first declaration of this declaration or itself if this
   /// is the only declaration.
   const decl_type *getFirstDeclaration() const {
     const decl_type *D = static_cast<const decl_type*>(this);
-    while (D->getPreviousDecl())
-      D = D->getPreviousDecl();
-    return D;
+    return const_cast<decl_type *>(D)->getFirstDeclaration();
   }
 
   /// \brief Returns true if this is the first declaration.
   bool isFirstDeclaration() const {
-    return RedeclLink.NextIsLatest();
+    return getFirstDeclaration() == this;
+  }
+
+  decl_type *getNextDecl() {
+    if (RedeclLink.NextIsFirst())
+      return 0;
+    return RedeclLink.getNext();
+  }
+
+  const decl_type *getNextDecl() const {
+    const decl_type *D = static_cast<const decl_type*>(this);
+    return const_cast<decl_type *>(D)->getNextDecl();
   }
 
   /// \brief Returns the most recent (re)declaration of this declaration.
   decl_type *getMostRecentDecl() {
-    return getFirstDeclaration()->RedeclLink.getNext();
+    decl_type *D = static_cast<decl_type*>(this);
+    decl_type *S;
+    while ((S = D->getNextDecl()))
+      D = S;
+    return D;
   }
 
   /// \brief Returns the most recent (re)declaration of this declaration.
   const decl_type *getMostRecentDecl() const {
-    return getFirstDeclaration()->RedeclLink.getNext();
+    const decl_type *D = static_cast<const decl_type*>(this);
+    return const_cast<decl_type *>(D)->getMostRecentDecl();
   }
-  
+
   /// \brief Set the previous declaration. If PrevDecl is NULL, set this as the
   /// first and only declaration.
   void setPreviousDeclaration(decl_type *PrevDecl);
@@ -144,7 +171,9 @@ public:
       }
 
       // Get either previous decl or latest decl.
-      decl_type *Next = Current->RedeclLink.getNext();
+      decl_type *Next = Current->getPreviousDecl();
+      if (!Next)
+        Next = Current->getMostRecentDecl();
       Current = (Next != Starter ? Next : 0);
       return *this;
     }
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index f14e4dc..e27996a 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -552,13 +552,13 @@ static LinkageInfo getLVForNamespaceScopeDecl(const NamedDecl *D,
         return LinkageInfo::internal();
     }
 
-    for (const VarDecl *PrevVar = Var->getPreviousDecl(); PrevVar;
-         PrevVar = PrevVar->getPreviousDecl()) {
-      if (PrevVar->getStorageClass() == SC_PrivateExtern &&
+    for (const VarDecl *I = Var->getFirstDeclaration(); I != Var;
+         I = I->getNextDecl()) {
+      if (I->getStorageClass() == SC_PrivateExtern &&
           Var->getStorageClass() == SC_None)
-        return PrevVar->getLinkageAndVisibility();
+        return I->getLinkageAndVisibility();
       // Explicitly declared static.
-      if (PrevVar->getStorageClass() == SC_Static)
+      if (I->getStorageClass() == SC_Static)
         return LinkageInfo::internal();
     }
   } else if (isa<FunctionDecl>(D) || isa<FunctionTemplateDecl>(D)) {
diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp
index 341f8eb..9c2c369 100644
--- a/lib/Serialization/ASTReaderDecl.cpp
+++ b/lib/Serialization/ASTReaderDecl.cpp
@@ -195,8 +195,8 @@ namespace clang {
         RawLocation(RawLocation), Record(Record), Idx(Idx),
         TypeIDForTypeDecl(0), HasPendingBody(false) { }
 
-    static void attachPreviousDecl(Decl *D, Decl *previous);
-    static void attachLatestDecl(Decl *D, Decl *latest);
+    static void attachNextDecl(Decl *D, Decl *Next);
+    static void attachFirstDecl(Decl *D, Decl *First);
 
     /// \brief Determine whether this declaration has a pending body.
     bool hasPendingBody() const { return HasPendingBody; }
@@ -1797,11 +1797,11 @@ ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
   T *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID));
   if (FirstDecl != D) {
     // We delay loading of the redeclaration chain to avoid deeply nested calls.
-    // We temporarily set the first (canonical) declaration as the previous one
-    // which is the one that matters and mark the real previous DeclID to be
+    // We temporarily set the first (canonical) declaration as the next one
+    // which is the one that matters and mark the real next DeclID to be
     // loaded & attached later on.
-    D->RedeclLink = Redeclarable<T>::PreviousDeclLink(FirstDecl);
-  }    
+    D->RedeclLink = Redeclarable<T>::FirstDeclLink(FirstDecl);
+  }
   
   // Note that this declaration has been deserialized.
   Reader.RedeclsDeserialized.insert(static_cast<T *>(D));
@@ -1837,7 +1837,7 @@ void ASTDeclReader::mergeRedeclarable(Redeclarable<T> *D, T *Existing,
     // Have our redeclaration link point back at the canonical declaration
     // of the existing declaration, so that this declaration has the 
     // appropriate canonical declaration.
-    D->RedeclLink = Redeclarable<T>::PreviousDeclLink(ExistingCanon);
+    D->RedeclLink = Redeclarable<T>::FirstDeclLink(ExistingCanon);
 
     // When we merge a namespace, update its pointer to the first namespace.
     if (NamespaceDecl *Namespace
@@ -2205,25 +2205,25 @@ ASTDeclReader::FindExistingResult ASTDeclReader::findExisting(NamedDecl *D) {
   return FindExistingResult(Reader);
 }
 
-void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *previous) {
-  assert(D && previous);
+void ASTDeclReader::attachNextDecl(Decl *D, Decl *Next) {
+  assert(D && Next);
   if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
-    TD->RedeclLink.setNext(cast<TagDecl>(previous));
+    TD->RedeclLink.setNext2(cast<TagDecl>(Next));
   } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
-    FD->RedeclLink.setNext(cast<FunctionDecl>(previous));
+    FD->RedeclLink.setNext2(cast<FunctionDecl>(Next));
   } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
-    VD->RedeclLink.setNext(cast<VarDecl>(previous));
+    VD->RedeclLink.setNext2(cast<VarDecl>(Next));
   } else if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D)) {
-    TD->RedeclLink.setNext(cast<TypedefNameDecl>(previous));
+    TD->RedeclLink.setNext2(cast<TypedefNameDecl>(Next));
   } else if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
-    ID->RedeclLink.setNext(cast<ObjCInterfaceDecl>(previous));
+    ID->RedeclLink.setNext2(cast<ObjCInterfaceDecl>(Next));
   } else if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D)) {
-    PD->RedeclLink.setNext(cast<ObjCProtocolDecl>(previous));
+    PD->RedeclLink.setNext2(cast<ObjCProtocolDecl>(Next));
   } else if (NamespaceDecl *ND = dyn_cast<NamespaceDecl>(D)) {
-    ND->RedeclLink.setNext(cast<NamespaceDecl>(previous));
+    ND->RedeclLink.setNext2(cast<NamespaceDecl>(Next));
   } else {
     RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D);
-    TD->RedeclLink.setNext(cast<RedeclarableTemplateDecl>(previous));
+    TD->RedeclLink.setNext2(cast<RedeclarableTemplateDecl>(Next));
   }
 
   // If the declaration was visible in one module, a redeclaration of it in
@@ -2231,43 +2231,30 @@ void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *previous) {
   //
   // FIXME: In this case, the declaration should only be visible if a module
   //        that makes it visible has been imported.
-  D->IdentifierNamespace |=
-      previous->IdentifierNamespace &
+  Next->IdentifierNamespace |=
+      D->IdentifierNamespace &
       (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
 }
 
-void ASTDeclReader::attachLatestDecl(Decl *D, Decl *Latest) {
-  assert(D && Latest);
+void ASTDeclReader::attachFirstDecl(Decl *D, Decl *First) {
+  assert(D && First);
   if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
-    TD->RedeclLink
-      = Redeclarable<TagDecl>::LatestDeclLink(cast<TagDecl>(Latest));
+    TD->RedeclLink.setFirst(cast<TagDecl>(First));
   } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
-    FD->RedeclLink 
-      = Redeclarable<FunctionDecl>::LatestDeclLink(cast<FunctionDecl>(Latest));
+    FD->RedeclLink.setFirst(cast<FunctionDecl>(First));
   } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
-    VD->RedeclLink
-      = Redeclarable<VarDecl>::LatestDeclLink(cast<VarDecl>(Latest));
+    VD->RedeclLink.setFirst(cast<VarDecl>(First));
   } else if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D)) {
-    TD->RedeclLink
-      = Redeclarable<TypedefNameDecl>::LatestDeclLink(
-                                                cast<TypedefNameDecl>(Latest));
+    TD->RedeclLink.setFirst(cast<TypedefNameDecl>(First));
   } else if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
-    ID->RedeclLink
-      = Redeclarable<ObjCInterfaceDecl>::LatestDeclLink(
-                                              cast<ObjCInterfaceDecl>(Latest));
+    ID->RedeclLink.setFirst(cast<ObjCInterfaceDecl>(First));
   } else if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D)) {
-    PD->RedeclLink
-      = Redeclarable<ObjCProtocolDecl>::LatestDeclLink(
-                                                cast<ObjCProtocolDecl>(Latest));
+    PD->RedeclLink.setFirst(cast<ObjCProtocolDecl>(First));
   } else if (NamespaceDecl *ND = dyn_cast<NamespaceDecl>(D)) {
-    ND->RedeclLink
-      = Redeclarable<NamespaceDecl>::LatestDeclLink(
-                                                   cast<NamespaceDecl>(Latest));
+    ND->RedeclLink.setFirst(cast<NamespaceDecl>(First));
   } else {
     RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D);
-    TD->RedeclLink
-      = Redeclarable<RedeclarableTemplateDecl>::LatestDeclLink(
-                                        cast<RedeclarableTemplateDecl>(Latest));
+    TD->RedeclLink.setFirst(cast<RedeclarableTemplateDecl>(First));
   }
 }
 
@@ -2735,11 +2722,12 @@ void ASTReader::loadPendingDeclChain(serialization::GlobalDeclID ID) {
     if (Chain[I] == CanonDecl)
       continue;
 
-    ASTDeclReader::attachPreviousDecl(Chain[I], MostRecent);
+
+    ASTDeclReader::attachNextDecl(MostRecent, Chain[I]);
     MostRecent = Chain[I];
   }
-  
-  ASTDeclReader::attachLatestDecl(CanonDecl, MostRecent);  
+
+  ASTDeclReader::attachFirstDecl(MostRecent, CanonDecl);
 }
 
 namespace {
