* Fix linking of opaque types and their non-opaque versions
authorChris Lattner <sabre@nondot.org>
Thu, 30 Jan 2003 20:53:43 +0000 (20:53 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 30 Jan 2003 20:53:43 +0000 (20:53 +0000)
* Fix bug: Linker/2003-01-30-LinkerTypeRename.ll

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5441 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Linker/LinkModules.cpp
lib/Transforms/Utils/Linker.cpp
lib/VMCore/Linker.cpp

index 5abbcfe81990f8071436c6628e988de160f7298c..60c6e03ae128b2b6a8348c617702b5ba319e105d 100644 (file)
@@ -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<Type>(DestST->lookup(Type::TypeTy, Name));
     if (Entry && !isa<OpaqueType>(Entry)) {  // Yup, the value already exists...
-      if (Entry != RHS && !isa<OpaqueType>(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<OpaqueType>(const_cast<Type*>(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<OpaqueType>(const_cast<Type*>(Entry));
+        OT->refineAbstractTypeTo(RHS);
+      }
+
       // TODO: FIXME WHEN TYPES AREN'T CONST
       DestST->insert(Name, const_cast<Type*>(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<Constant>(RemapOperand(SGV->getInitializer(), ValueMap));
+        cast<Constant>(RemapOperand(SGV->getInitializer(), ValueMap, 0));
 
       GlobalVariable *DGV = cast<GlobalVariable>(ValueMap[SGV]);    
       if (DGV->hasInitializer() && SGV->hasExternalLinkage() &&
index 5abbcfe81990f8071436c6628e988de160f7298c..60c6e03ae128b2b6a8348c617702b5ba319e105d 100644 (file)
@@ -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<Type>(DestST->lookup(Type::TypeTy, Name));
     if (Entry && !isa<OpaqueType>(Entry)) {  // Yup, the value already exists...
-      if (Entry != RHS && !isa<OpaqueType>(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<OpaqueType>(const_cast<Type*>(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<OpaqueType>(const_cast<Type*>(Entry));
+        OT->refineAbstractTypeTo(RHS);
+      }
+
       // TODO: FIXME WHEN TYPES AREN'T CONST
       DestST->insert(Name, const_cast<Type*>(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<Constant>(RemapOperand(SGV->getInitializer(), ValueMap));
+        cast<Constant>(RemapOperand(SGV->getInitializer(), ValueMap, 0));
 
       GlobalVariable *DGV = cast<GlobalVariable>(ValueMap[SGV]);    
       if (DGV->hasInitializer() && SGV->hasExternalLinkage() &&
index 5abbcfe81990f8071436c6628e988de160f7298c..60c6e03ae128b2b6a8348c617702b5ba319e105d 100644 (file)
@@ -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<Type>(DestST->lookup(Type::TypeTy, Name));
     if (Entry && !isa<OpaqueType>(Entry)) {  // Yup, the value already exists...
-      if (Entry != RHS && !isa<OpaqueType>(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<OpaqueType>(const_cast<Type*>(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<OpaqueType>(const_cast<Type*>(Entry));
+        OT->refineAbstractTypeTo(RHS);
+      }
+
       // TODO: FIXME WHEN TYPES AREN'T CONST
       DestST->insert(Name, const_cast<Type*>(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<Constant>(RemapOperand(SGV->getInitializer(), ValueMap));
+        cast<Constant>(RemapOperand(SGV->getInitializer(), ValueMap, 0));
 
       GlobalVariable *DGV = cast<GlobalVariable>(ValueMap[SGV]);    
       if (DGV->hasInitializer() && SGV->hasExternalLinkage() &&