Clang used to error out on the attached testcase, due to multiple definitions of foo<int>. The problem is that multiple FunctionTemplateDecl::Common pointers are created for the two FunctionTemplateDeclarations foo in the redeclaration chain, each with their own copy of the instantiation of f<int>.
This patch fixes the problem by using the previous function template in a call to FuntionTemplateDecl::getInjectedTemplateArgs() (this was the call that caused the Common pointer to be allocated in the redeclaration). Most of this patch is just boilerplate to get the function template declaration down the stack to where it's needed.
Fixes rdar://44810129
Thanks for taking a look!
Erik