Revert r122143 through r122140, which collectively broke the LLVMC tests on
the buildbots.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122149 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp
index f6c7d03..dd0b07e 100644
--- a/lib/Linker/LinkModules.cpp
+++ b/lib/Linker/LinkModules.cpp
@@ -449,7 +449,7 @@
     const NamedMDNode *SrcNMD = I;
     NamedMDNode *DestNMD = Dest->getOrInsertNamedMetadata(SrcNMD->getName());
     // Add Src elements into Dest node.
-    for (unsigned i = 0, e = SrcNMD->getNumOperands(); i != e; ++i)
+    for (unsigned i = 0, e = SrcNMD->getNumOperands(); i != e; ++i) 
       DestNMD->addOperand(cast<MDNode>(MapValue(SrcNMD->getOperand(i),
                                                 ValueMap,
                                                 true)));
@@ -559,14 +559,14 @@
       // we are replacing may be a function (if a prototype, weak, etc) or a
       // global variable.
       GlobalVariable *NewDGV =
-        new GlobalVariable(*Dest, SGV->getType()->getElementType(),
-                           SGV->isConstant(), NewLinkage, /*init*/0,
+        new GlobalVariable(*Dest, SGV->getType()->getElementType(), 
+                           SGV->isConstant(), NewLinkage, /*init*/0, 
                            DGV->getName(), 0, false,
                            SGV->getType()->getAddressSpace());
 
       // Propagate alignment, section, and visibility info.
       CopyGVAttributes(NewDGV, SGV);
-      DGV->replaceAllUsesWith(ConstantExpr::getBitCast(NewDGV,
+      DGV->replaceAllUsesWith(ConstantExpr::getBitCast(NewDGV, 
                                                               DGV->getType()));
 
       // DGV will conflict with NewDGV because they both had the same
@@ -928,7 +928,7 @@
       CopyGVAttributes(NewDF, SF);
 
       // Any uses of DF need to change to NewDF, with cast
-      DGV->replaceAllUsesWith(ConstantExpr::getBitCast(NewDF,
+      DGV->replaceAllUsesWith(ConstantExpr::getBitCast(NewDF, 
                                                               DGV->getType()));
 
       // DF will conflict with NewDF because they both had the same. We must
@@ -1017,7 +1017,7 @@
         Value *Old = MI->second;
         if (!isa<Instruction>(Old) && !isa<BasicBlock>(Old)) {
           Value *New = MapValue(Old, ValueMap, true);
-          if (New != Old)
+          if (New != Old) 
             I->setMetadata(MI->first, cast<MDNode>(New));
         }
       }
@@ -1100,7 +1100,7 @@
          "Appending variables with different section name need to be linked!");
 
       unsigned NewSize = T1->getNumElements() + T2->getNumElements();
-      ArrayType *NewType = ArrayType::get(T1->getElementType(),
+      ArrayType *NewType = ArrayType::get(T1->getElementType(), 
                                                          NewSize);
 
       G1->setName("");   // Clear G1's name in case of a conflict!
@@ -1144,7 +1144,7 @@
       // getelementptr instructions to not use the Cast!
       G1->replaceAllUsesWith(ConstantExpr::getBitCast(NG,
                              G1->getType()));
-      G2->replaceAllUsesWith(ConstantExpr::getBitCast(NG,
+      G2->replaceAllUsesWith(ConstantExpr::getBitCast(NG, 
                              G2->getType()));
 
       // Remove the two globals from the module now...
@@ -1301,9 +1301,10 @@
 
   // If the source library's module id is in the dependent library list of the
   // destination library, remove it since that module is now linked in.
-  const std::string &modId = Src->getModuleIdentifier();
-  if (!modId.empty())
-    Dest->removeLibrary(sys::path::stem(modId));
+  sys::Path modId;
+  modId.set(Src->getModuleIdentifier());
+  if (!modId.isEmpty())
+    Dest->removeLibrary(modId.getBasename());
 
   return false;
 }