This fixed is based on the assert in LinkageComputer::getLVForDecl(…) which assumes that all the decls in a redecl chain have the same linkage.
This change was trigged by a bug that came up when debugging llc and running the following expression in while in `SelectionDAG::getNode(…)
p VT.getVectorElementType() == Operand.getValueType()
Evaluating this expression leads to import of an operator== for I believe a std::set iterator. One with external linkage and one with unique external linkage but they end in the same redecl chain which triggers the assert in LinkageComputer::getLVForDecl(…).
This case has proven difficult to reduce to a minimal test case.
This would be equivalent but more clear code (formatting is probably not correct here):
if (Found->getLinkageInternal() != From->getLinkageInternal()) return false; if (From->hasExternalFormalLinkage()) return true; return Importer.GetFromTU(Found) == From->getTranslationUnitDecl() && From->isInAnonymousNamespace() == Found->isInAnonymousNamespace();