diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index 5abbcfe8199..60c6e03ae12 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -45,13 +45,23 @@ static bool LinkTypes(Module *Dest, const Module *Src, std::string *Err) { // Check to see if this type name is already in the dest module... const Type *Entry = cast_or_null(DestST->lookup(Type::TypeTy, Name)); if (Entry && !isa(Entry)) { // Yup, the value already exists... - if (Entry != RHS && !isa(RHS)) - // If it's the same, noop. Otherwise, error. - return Error(Err, "Type named '" + Name + - "' of different shape in modules.\n Src='" + - Entry->getDescription() + "'.\n Dst='" + - RHS->getDescription() + "'"); + if (Entry != RHS) { + if (OpaqueType *OT = dyn_cast(const_cast(RHS))) { + OT->refineAbstractTypeTo(Entry); + } else { + // If it's the same, noop. Otherwise, error. + return Error(Err, "Type named '" + Name + + "' of different shape in modules.\n Src='" + + Entry->getDescription() + "'.\n Dst='" + + RHS->getDescription() + "'"); + } + } } else { // Type not in dest module. Add it now. + if (Entry) { + OpaqueType *OT = cast(const_cast(Entry)); + OT->refineAbstractTypeTo(RHS); + } + // TODO: FIXME WHEN TYPES AREN'T CONST DestST->insert(Name, const_cast(RHS)); } @@ -236,7 +246,7 @@ static bool LinkGlobalInits(Module *Dest, const Module *Src, if (SGV->hasInitializer()) { // Only process initialized GV's // Figure out what the initializer looks like in the dest module... Constant *DInit = - cast(RemapOperand(SGV->getInitializer(), ValueMap)); + cast(RemapOperand(SGV->getInitializer(), ValueMap, 0)); GlobalVariable *DGV = cast(ValueMap[SGV]); if (DGV->hasInitializer() && SGV->hasExternalLinkage() && diff --git a/lib/Transforms/Utils/Linker.cpp b/lib/Transforms/Utils/Linker.cpp index 5abbcfe8199..60c6e03ae12 100644 --- a/lib/Transforms/Utils/Linker.cpp +++ b/lib/Transforms/Utils/Linker.cpp @@ -45,13 +45,23 @@ static bool LinkTypes(Module *Dest, const Module *Src, std::string *Err) { // Check to see if this type name is already in the dest module... const Type *Entry = cast_or_null(DestST->lookup(Type::TypeTy, Name)); if (Entry && !isa(Entry)) { // Yup, the value already exists... - if (Entry != RHS && !isa(RHS)) - // If it's the same, noop. Otherwise, error. - return Error(Err, "Type named '" + Name + - "' of different shape in modules.\n Src='" + - Entry->getDescription() + "'.\n Dst='" + - RHS->getDescription() + "'"); + if (Entry != RHS) { + if (OpaqueType *OT = dyn_cast(const_cast(RHS))) { + OT->refineAbstractTypeTo(Entry); + } else { + // If it's the same, noop. Otherwise, error. + return Error(Err, "Type named '" + Name + + "' of different shape in modules.\n Src='" + + Entry->getDescription() + "'.\n Dst='" + + RHS->getDescription() + "'"); + } + } } else { // Type not in dest module. Add it now. + if (Entry) { + OpaqueType *OT = cast(const_cast(Entry)); + OT->refineAbstractTypeTo(RHS); + } + // TODO: FIXME WHEN TYPES AREN'T CONST DestST->insert(Name, const_cast(RHS)); } @@ -236,7 +246,7 @@ static bool LinkGlobalInits(Module *Dest, const Module *Src, if (SGV->hasInitializer()) { // Only process initialized GV's // Figure out what the initializer looks like in the dest module... Constant *DInit = - cast(RemapOperand(SGV->getInitializer(), ValueMap)); + cast(RemapOperand(SGV->getInitializer(), ValueMap, 0)); GlobalVariable *DGV = cast(ValueMap[SGV]); if (DGV->hasInitializer() && SGV->hasExternalLinkage() && diff --git a/lib/VMCore/Linker.cpp b/lib/VMCore/Linker.cpp index 5abbcfe8199..60c6e03ae12 100644 --- a/lib/VMCore/Linker.cpp +++ b/lib/VMCore/Linker.cpp @@ -45,13 +45,23 @@ static bool LinkTypes(Module *Dest, const Module *Src, std::string *Err) { // Check to see if this type name is already in the dest module... const Type *Entry = cast_or_null(DestST->lookup(Type::TypeTy, Name)); if (Entry && !isa(Entry)) { // Yup, the value already exists... - if (Entry != RHS && !isa(RHS)) - // If it's the same, noop. Otherwise, error. - return Error(Err, "Type named '" + Name + - "' of different shape in modules.\n Src='" + - Entry->getDescription() + "'.\n Dst='" + - RHS->getDescription() + "'"); + if (Entry != RHS) { + if (OpaqueType *OT = dyn_cast(const_cast(RHS))) { + OT->refineAbstractTypeTo(Entry); + } else { + // If it's the same, noop. Otherwise, error. + return Error(Err, "Type named '" + Name + + "' of different shape in modules.\n Src='" + + Entry->getDescription() + "'.\n Dst='" + + RHS->getDescription() + "'"); + } + } } else { // Type not in dest module. Add it now. + if (Entry) { + OpaqueType *OT = cast(const_cast(Entry)); + OT->refineAbstractTypeTo(RHS); + } + // TODO: FIXME WHEN TYPES AREN'T CONST DestST->insert(Name, const_cast(RHS)); } @@ -236,7 +246,7 @@ static bool LinkGlobalInits(Module *Dest, const Module *Src, if (SGV->hasInitializer()) { // Only process initialized GV's // Figure out what the initializer looks like in the dest module... Constant *DInit = - cast(RemapOperand(SGV->getInitializer(), ValueMap)); + cast(RemapOperand(SGV->getInitializer(), ValueMap, 0)); GlobalVariable *DGV = cast(ValueMap[SGV]); if (DGV->hasInitializer() && SGV->hasExternalLinkage() &&