    if (!Reader.getContext().getLangOpts().Modules)
      return;
    
-@@ -1731,7 +1739,16 @@
+@@ -1731,7 +1739,7 @@
      return (FuncX->getLinkage() == FuncY->getLinkage()) &&
        FuncX->getASTContext().hasSameType(FuncX->getType(), FuncY->getType());
    }
 -  
-+
-+  if (const FunctionTemplateDecl* FTDX = dyn_cast<FunctionTemplateDecl>(X)) {
-+    const FunctionTemplateDecl* FTDY = cast<FunctionTemplateDecl>(Y);
-+    if (isSameEntity(FTDX->getTemplatedDecl(), FTDY->getTemplatedDecl())) {
-+      return FTDX->getTemplatedDecl()->getNumParams() 
-+        == FTDY->getTemplatedDecl()->getNumParams();
-+
-+    }
-+  }
 +    
    // Variables with the same type and linkage match.
    if (VarDecl *VarX = dyn_cast<VarDecl>(X)) {
      VarDecl *VarY = cast<VarDecl>(Y);
-@@ -1744,20 +1761,26 @@
+@@ -1744,20 +1752,26 @@
      NamespaceDecl *NamespaceY = cast<NamespaceDecl>(Y);
      return NamespaceX->isInline() == NamespaceY->isInline();
    }

         return FindExistingResult(Reader, D, *R.first);
     }
   }
@@ -1798,22 +1823,41 @@
 void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *previous) {
   assert(D && previous);
   if (TagDecl *TD = dyn_cast<TagDecl>(D)) {

   void ClearFileInfo() {
Index: tools/clang/lib/Serialization/ASTReaderDecl.cpp
===================================================================
--- tools/clang/lib/Serialization/ASTReaderDecl.cpp	(revision 161724)
+++ tools/clang/lib/Serialization/ASTReaderDecl.cpp	(working copy)
@@ -520,7 +520,9 @@
   FD->IsConstexpr = Record[Idx++];
