summaryrefslogtreecommitdiffstats
path: root/lib/Linker/LinkModules.cpp
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2012-02-27 23:48:30 +0000
committerBill Wendling <isanbard@gmail.com>2012-02-27 23:48:30 +0000
commit348e5e763e1297870878c5cb11aadfab2e8e5e7a (patch)
treec60b8f6416d89fd0cd4f6be9190c3b6d3173baa7 /lib/Linker/LinkModules.cpp
parente879cbae7cf80f4653860d69e50f667d45401fd9 (diff)
downloadexternal_llvm-348e5e763e1297870878c5cb11aadfab2e8e5e7a.zip
external_llvm-348e5e763e1297870878c5cb11aadfab2e8e5e7a.tar.gz
external_llvm-348e5e763e1297870878c5cb11aadfab2e8e5e7a.tar.bz2
Add back removed code. It still causes LLVM to miscompile. But not having it breaks other things.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@151594 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Linker/LinkModules.cpp')
-rw-r--r--lib/Linker/LinkModules.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp
index e87d6dd..8af2c88 100644
--- a/lib/Linker/LinkModules.cpp
+++ b/lib/Linker/LinkModules.cpp
@@ -581,6 +581,36 @@ void ModuleLinker::computeTypeMapping() {
TypeMap.addTypeMapping(DGV->getType(), I->getType());
}
+ // Incorporate types by name, scanning all the types in the source module.
+ // At this point, the destination module may have a type "%foo = { i32 }" for
+ // example. When the source module got loaded into the same LLVMContext, if
+ // it had the same type, it would have been renamed to "%foo.42 = { i32 }".
+ // Though it isn't required for correctness, attempt to link these up to clean
+ // up the IR.
+ std::vector<StructType*> SrcStructTypes;
+ SrcM->findUsedStructTypes(SrcStructTypes);
+
+ SmallPtrSet<StructType*, 32> SrcStructTypesSet(SrcStructTypes.begin(),
+ SrcStructTypes.end());
+
+ for (unsigned i = 0, e = SrcStructTypes.size(); i != e; ++i) {
+ StructType *ST = SrcStructTypes[i];
+ if (!ST->hasName()) continue;
+
+ // Check to see if there is a dot in the name followed by a digit.
+ size_t DotPos = ST->getName().rfind('.');
+ if (DotPos == 0 || DotPos == StringRef::npos ||
+ ST->getName().back() == '.' || !isdigit(ST->getName()[DotPos+1]))
+ continue;
+
+ // Check to see if the destination module has a struct with the prefix name.
+ if (StructType *DST = DstM->getTypeByName(ST->getName().substr(0, DotPos)))
+ // 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);
+ }
+
// Don't bother incorporating aliases, they aren't generally typed well.
// Now that we have discovered all of the type equivalences, get a body for