Index: lib/Linker/LinkModules.cpp =================================================================== --- lib/Linker/LinkModules.cpp +++ lib/Linker/LinkModules.cpp @@ -98,6 +98,8 @@ Type *remapType(Type *SrcTy) override { return get(SrcTy); } bool areTypesIsomorphic(Type *DstTy, Type *SrcTy); + + void addTrivialMapRecursively(Type *Ty); }; } @@ -142,7 +144,7 @@ // Two identical types are clearly isomorphic. Remember this // non-speculatively. if (DstTy == SrcTy) { - Entry = DstTy; + addTrivialMapRecursively(DstTy); return true; } @@ -214,6 +216,22 @@ return true; } +/// For types which turn out to be the same Type instance in both modules, +/// remembers this fact for it and all the contained types. +/// +/// We need to be aware of this when performing the instruction rewrites +/// laster on. +void TypeMapTy::addTrivialMapRecursively(Type *Ty) { + Type *&Entry = MappedTypes[Ty]; + if (Entry) + return; + + Entry = Ty; + for (unsigned I = 0, E = Ty->getNumContainedTypes(); I != E; ++I) { + addTrivialMapRecursively(Ty->getContainedType(I)); + } +} + void TypeMapTy::linkDefinedTypeBodies() { SmallVector Elements; for (StructType *SrcSTy : SrcDefinitionsToResolve) {