summaryrefslogtreecommitdiffstats
path: root/llvm/lib/VMCore/Module.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-05-15 19:37:21 +0000
committerChris Lattner <sabre@nondot.org>2003-05-15 19:37:21 +0000
commitcb4d26fb9576fa0d3a98082039d2763f9f5f71f7 (patch)
tree5a126e5fafb64595b5784d37fa9b8824ed5f6439 /llvm/lib/VMCore/Module.cpp
parent1b17357e92922f87127a58d8a103aecfe18c9066 (diff)
downloadbcm5719-llvm-cb4d26fb9576fa0d3a98082039d2763f9f5f71f7.tar.gz
bcm5719-llvm-cb4d26fb9576fa0d3a98082039d2763f9f5f71f7.zip
Fix bug: Assembler/2003-05-15-AssemblerProblem.llx
llvm-svn: 6234
Diffstat (limited to 'llvm/lib/VMCore/Module.cpp')
-rw-r--r--llvm/lib/VMCore/Module.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/llvm/lib/VMCore/Module.cpp b/llvm/lib/VMCore/Module.cpp
index fe9b828b2b9..275d4cfbf31 100644
--- a/llvm/lib/VMCore/Module.cpp
+++ b/llvm/lib/VMCore/Module.cpp
@@ -250,6 +250,7 @@ void Module::destroyConstantPointerRef(ConstantPointerRef *CPR) {
}
void Module::mutateConstantPointerRef(GlobalValue *OldGV, GlobalValue *NewGV) {
+ assert(OldGV != NewGV && "Cannot mutate to the same global!");
GlobalValueRefMap::iterator I = GVRefMap->Map.find(OldGV);
assert(I != GVRefMap->Map.end() &&
"mutateConstantPointerRef; OldGV not in table!");
@@ -258,6 +259,16 @@ void Module::mutateConstantPointerRef(GlobalValue *OldGV, GlobalValue *NewGV) {
// Remove the old entry...
GVRefMap->Map.erase(I);
- // Insert the new entry...
- GVRefMap->Map.insert(std::make_pair(NewGV, Ref));
+ // Check to see if a CPR already exists for NewGV
+ I = GVRefMap->Map.lower_bound(NewGV);
+
+ if (I == GVRefMap->Map.end() || I->first != NewGV) {
+ // Insert the new entry...
+ GVRefMap->Map.insert(I, std::make_pair(NewGV, Ref));
+ } else {
+ // Otherwise, an entry already exists for the current global value.
+ // Completely replace the old CPR with the existing one...
+ Ref->replaceAllUsesWith(I->second);
+ delete Ref;
+ }
}
OpenPOWER on IntegriCloud