diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index 4f6013e7020..ba4221d0539 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -148,6 +148,7 @@ bool TypeMapTy::areTypesIsomorphic(Type *DstTy, Type *SrcTy) { if (PointerType *PT = dyn_cast(DstTy)) { if (PT->getAddressSpace() != cast(SrcTy)->getAddressSpace()) return false; + } else if (FunctionType *FT = dyn_cast(DstTy)) { if (FT->isVarArg() != cast(SrcTy)->isVarArg()) return false; @@ -567,6 +568,9 @@ void ModuleLinker::computeTypeMapping() { std::vector SrcStructTypes; SrcM->findUsedStructTypes(SrcStructTypes); + SmallPtrSet SrcStructTypesSet(SrcStructTypes.begin(), + SrcStructTypes.end()); + for (unsigned i = 0, e = SrcStructTypes.size(); i != e; ++i) { StructType *ST = SrcStructTypes[i]; if (!ST->hasName()) continue; @@ -579,7 +583,10 @@ void ModuleLinker::computeTypeMapping() { // Check to see if the destination module has a struct with the prefix name. if (StructType *DST = DstM->getTypeByName(ST->getName().substr(0, DotPos))) - TypeMap.addTypeMapping(DST, ST); + // Don't use it if this actually came from the source module. They're in + // the same LLVMContext after all. + if (!SrcStructTypesSet.count(DST)) + TypeMap.addTypeMapping(DST, ST); }