summaryrefslogtreecommitdiff
path: root/lib/VMCore
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-07-30 19:04:37 +0000
committerChris Lattner <sabre@nondot.org>2003-07-30 19:04:37 +0000
commit61972242f3983263c6f715ad31d80cdb06031837 (patch)
tree19d6b477fb27704050c89ace500150b5bcadeb8f /lib/VMCore
parent800e6e216abaf93e7cc297af0e1e78f24b2d6143 (diff)
downloadllvm-61972242f3983263c6f715ad31d80cdb06031837.tar.gz
llvm-61972242f3983263c6f715ad31d80cdb06031837.tar.bz2
llvm-61972242f3983263c6f715ad31d80cdb06031837.tar.xz
Fix a bug that brian reported
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7428 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r--lib/VMCore/Constants.cpp28
1 files changed, 24 insertions, 4 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index 7bbbdb3202..ab4bdb390b 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -463,6 +463,26 @@ void ConstantExpr::replaceUsesOfWithOnConstant(Value *From, Value *ToV) {
//===----------------------------------------------------------------------===//
// Factory Function Implementation
+// ReplaceUsesOfWith - This is exactly the same as Value::replaceAllUsesWith,
+// except that it doesn't have all of the asserts. The asserts fail because we
+// are half-way done resolving types, which causes some types to exist as two
+// different Type*'s at the same time. This is a sledgehammer to work around
+// this problem.
+//
+static void ReplaceUsesOfWith(Value *Old, Value *New) {
+ while (!Old->use_empty()) {
+ User *Use = Old->use_back();
+ // Must handle Constants specially, we cannot call replaceUsesOfWith on a
+ // constant!
+ if (Constant *C = dyn_cast<Constant>(Use)) {
+ C->replaceUsesOfWithOnConstant(Old, New);
+ } else {
+ Use->replaceUsesOfWith(Old, New);
+ }
+ }
+}
+
+
// ConstantCreator - A class that is used to create constants by
// ValueMap*. This class should be partially specialized if there is
// something strange that needs to be done to interface to the ctor for the
@@ -573,7 +593,7 @@ void ConstantArray::refineAbstractType(const DerivedType *OldTy,
C.push_back(cast<Constant>(getOperand(i)));
Constant *New = ConstantArray::get(cast<ArrayType>(NewTy), C);
if (New != this) {
- replaceAllUsesWith(New);
+ ReplaceUsesOfWith(this, New);
destroyConstant(); // This constant is now dead, destroy it.
}
}
@@ -642,7 +662,7 @@ void ConstantStruct::refineAbstractType(const DerivedType *OldTy,
C.push_back(cast<Constant>(getOperand(i)));
Constant *New = ConstantStruct::get(cast<StructType>(NewTy), C);
if (New != this) {
- replaceAllUsesWith(New);
+ ReplaceUsesOfWith(this, New);
destroyConstant(); // This constant is now dead, destroy it.
}
}
@@ -683,7 +703,7 @@ void ConstantPointerNull::refineAbstractType(const DerivedType *OldTy,
// Make everyone now use a constant of the new type...
Constant *New = ConstantPointerNull::get(cast<PointerType>(NewTy));
if (New != this) {
- replaceAllUsesWith(New);
+ ReplaceUsesOfWith(this, New);
// This constant is now dead, destroy it.
destroyConstant();
@@ -836,7 +856,7 @@ void ConstantExpr::refineAbstractType(const DerivedType *OldTy,
New = ConstantExpr::getGetElementPtr(getOperand(0), C);
}
if (New != this) {
- replaceAllUsesWith(New);
+ ReplaceUsesOfWith(this, New);
destroyConstant(); // This constant is now dead, destroy it.
}
}