simplify this code by using value::takename
authorChris Lattner <sabre@nondot.org>
Sun, 11 Feb 2007 00:39:38 +0000 (00:39 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 11 Feb 2007 00:39:38 +0000 (00:39 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34172 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Linker/LinkModules.cpp

index 83765345bb1d755c120e1094f50032062d187d29..f7accb7719c6c779eb4c7f8752ce1117771fb865 100644 (file)
@@ -337,18 +337,15 @@ static void ForceRenaming(GlobalValue *GV, const std::string &Name) {
   ValueSymbolTable &ST = GV->getParent()->getValueSymbolTable();
 
   // If there is a conflict, rename the conflict.
-  GlobalValue *ConflictGV = cast_or_null<GlobalValue>(ST.lookup(Name));
-  if (ConflictGV) {
+  if (GlobalValue *ConflictGV = cast_or_null<GlobalValue>(ST.lookup(Name))) {
     assert(ConflictGV->hasInternalLinkage() &&
            "Not conflicting with a static global, should link instead!");
-    ConflictGV->setName("");        // Eliminate the conflict
-  }
-  GV->setName(Name);              // Force the name back
-  if (ConflictGV) {
-    ConflictGV->setName(Name);      // This will cause ConflictGV to get renamed
+    GV->takeName(ConflictGV);
+    ConflictGV->setName(Name);    // This will cause ConflictGV to get renamed
     assert(ConflictGV->getName() != Name && "ForceRenaming didn't work");
+  } else {
+    GV->setName(Name);              // Force the name back
   }
-  assert(GV->getName() == Name && "ForceRenaming didn't work");
 }
 
 /// CopyGVAttributes - copy additional attributes (those not needed to construct