Fix problem linking in a method prototype when a method body exists
authorChris Lattner <sabre@nondot.org>
Tue, 23 Oct 2001 20:43:42 +0000 (20:43 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 23 Oct 2001 20:43:42 +0000 (20:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@965 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 33acbb4afb2ae7c918f55271393915bec96300fe..55023b82bf9723a856396bc26b663b7d7dd52b74 100644 (file)
@@ -294,12 +294,20 @@ static bool LinkMethodBodies(Module *Dest, const Module *Src,
   // Loop over all of the methods in the src module, mapping them over as we go
   //
   for (Module::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
-    const Method *SM = *I;                   // Source Method
-    Method *DM = cast<Method>(ValueMap[SM]); // Destination method
+    const Method *SM = *I;                     // Source Method
+    if (!SM->isExternal()) {                   // No body if method is external
+      Method *DM = cast<Method>(ValueMap[SM]); // Destination method
+
+      // DM not external SM external?
+      if (!DM->isExternal()) {
+        if (Err)
+          *Err = "Method '" + (SM->hasName() ? SM->getName() : string("")) +
+                 "' body multiply defined!";
+        return true;
+      }
 
-    assert(DM && DM->isExternal() && "LinkMethodProtos failed!");
-    if (!SM->isExternal())  // External methods are already done
       if (LinkMethodBody(DM, SM, ValueMap, Err)) return true;
+    }
   }
   return false;
 }
index 33acbb4afb2ae7c918f55271393915bec96300fe..55023b82bf9723a856396bc26b663b7d7dd52b74 100644 (file)
@@ -294,12 +294,20 @@ static bool LinkMethodBodies(Module *Dest, const Module *Src,
   // Loop over all of the methods in the src module, mapping them over as we go
   //
   for (Module::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
-    const Method *SM = *I;                   // Source Method
-    Method *DM = cast<Method>(ValueMap[SM]); // Destination method
+    const Method *SM = *I;                     // Source Method
+    if (!SM->isExternal()) {                   // No body if method is external
+      Method *DM = cast<Method>(ValueMap[SM]); // Destination method
+
+      // DM not external SM external?
+      if (!DM->isExternal()) {
+        if (Err)
+          *Err = "Method '" + (SM->hasName() ? SM->getName() : string("")) +
+                 "' body multiply defined!";
+        return true;
+      }
 
-    assert(DM && DM->isExternal() && "LinkMethodProtos failed!");
-    if (!SM->isExternal())  // External methods are already done
       if (LinkMethodBody(DM, SM, ValueMap, Err)) return true;
+    }
   }
   return false;
 }
index 33acbb4afb2ae7c918f55271393915bec96300fe..55023b82bf9723a856396bc26b663b7d7dd52b74 100644 (file)
@@ -294,12 +294,20 @@ static bool LinkMethodBodies(Module *Dest, const Module *Src,
   // Loop over all of the methods in the src module, mapping them over as we go
   //
   for (Module::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
-    const Method *SM = *I;                   // Source Method
-    Method *DM = cast<Method>(ValueMap[SM]); // Destination method
+    const Method *SM = *I;                     // Source Method
+    if (!SM->isExternal()) {                   // No body if method is external
+      Method *DM = cast<Method>(ValueMap[SM]); // Destination method
+
+      // DM not external SM external?
+      if (!DM->isExternal()) {
+        if (Err)
+          *Err = "Method '" + (SM->hasName() ? SM->getName() : string("")) +
+                 "' body multiply defined!";
+        return true;
+      }
 
-    assert(DM && DM->isExternal() && "LinkMethodProtos failed!");
-    if (!SM->isExternal())  // External methods are already done
       if (LinkMethodBody(DM, SM, ValueMap, Err)) return true;
+    }
   }
   return false;
 }