[llvm-commits] CVS: llvm/lib/VMCore/Constants.cpp
Chris Lattner
lattner at cs.uiuc.edu
Wed Jul 30 14:05:02 PDT 2003
Changes in directory llvm/lib/VMCore:
Constants.cpp updated: 1.47 -> 1.48
---
Log message:
Fix a bug that brian reported
---
Diffs of the changes:
Index: llvm/lib/VMCore/Constants.cpp
diff -u llvm/lib/VMCore/Constants.cpp:1.47 llvm/lib/VMCore/Constants.cpp:1.48
--- llvm/lib/VMCore/Constants.cpp:1.47 Wed Jul 23 10:22:26 2003
+++ llvm/lib/VMCore/Constants.cpp Wed Jul 30 14:04:37 2003
@@ -463,6 +463,26 @@
//===----------------------------------------------------------------------===//
// 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 @@
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 @@
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 @@
// 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 @@
New = ConstantExpr::getGetElementPtr(getOperand(0), C);
}
if (New != this) {
- replaceAllUsesWith(New);
+ ReplaceUsesOfWith(this, New);
destroyConstant(); // This constant is now dead, destroy it.
}
}
More information about the llvm-commits
mailing list