[llvm-commits] CVS: llvm/lib/VMCore/Constants.cpp
Chris Lattner
lattner at cs.uiuc.edu
Mon Jun 16 07:12:01 PDT 2003
Changes in directory llvm/lib/VMCore:
Constants.cpp updated: 1.44 -> 1.45
---
Log message:
Fix bug: Linker/2003-06-02-TypeResolveProblem2.ll
---
Diffs of the changes:
Index: llvm/lib/VMCore/Constants.cpp
diff -u llvm/lib/VMCore/Constants.cpp:1.44 llvm/lib/VMCore/Constants.cpp:1.45
--- llvm/lib/VMCore/Constants.cpp:1.44 Mon Jun 2 12:42:47 2003
+++ llvm/lib/VMCore/Constants.cpp Mon Jun 16 07:11:33 2003
@@ -225,7 +225,9 @@
"Invalid initializer vector for constant structure");
Operands.reserve(V.size());
for (unsigned i = 0, e = V.size(); i != e; ++i) {
- assert(V[i]->getType() == ETypes[i] &&
+ assert((V[i]->getType() == ETypes[i] ||
+ (ETypes[i]->isAbstract() &&
+ ETypes[i]->getPrimitiveID()==V[i]->getType()->getPrimitiveID())) &&
"Initializer for struct element doesn't match struct element type!");
Operands.push_back(Use(V[i], this));
}
@@ -563,9 +565,11 @@
std::vector<Constant*> C;
for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
C.push_back(cast<Constant>(getOperand(i)));
- replaceAllUsesWith(ConstantArray::get(cast<ArrayType>(NewTy),
- C));
- destroyConstant(); // This constant is now dead, destroy it.
+ Constant *New = ConstantArray::get(cast<ArrayType>(NewTy), C);
+ if (New != this) {
+ replaceAllUsesWith(New);
+ destroyConstant(); // This constant is now dead, destroy it.
+ }
}
@@ -633,9 +637,11 @@
std::vector<Constant*> C;
for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
C.push_back(cast<Constant>(getOperand(i)));
- replaceAllUsesWith(ConstantStruct::get(cast<StructType>(NewTy),
- C));
- destroyConstant(); // This constant is now dead, destroy it.
+ Constant *New = ConstantStruct::get(cast<StructType>(NewTy), C);
+ if (New != this) {
+ replaceAllUsesWith(New);
+ destroyConstant(); // This constant is now dead, destroy it.
+ }
}
@@ -672,10 +678,13 @@
if (OldTy == NewTy) return;
// Make everyone now use a constant of the new type...
- replaceAllUsesWith(ConstantPointerNull::get(cast<PointerType>(NewTy)));
+ Constant *New = ConstantPointerNull::get(cast<PointerType>(NewTy));
+ if (New != this) {
+ replaceAllUsesWith(New);
- // This constant is now dead, destroy it.
- destroyConstant();
+ // This constant is now dead, destroy it.
+ destroyConstant();
+ }
}
@@ -806,13 +815,14 @@
// ::get methods intuit the type of the result based on the types of the
// operands. The operand types may not have had their types resolved yet.
//
+ Constant *New;
if (getOpcode() == Instruction::Cast) {
- replaceAllUsesWith(getCast(getOperand(0), NewTy));
+ New = getCast(getOperand(0), NewTy);
} else if (getOpcode() >= Instruction::BinaryOpsBegin &&
getOpcode() < Instruction::BinaryOpsEnd) {
- replaceAllUsesWith(get(getOpcode(), getOperand(0), getOperand(0)));
+ New = get(getOpcode(), getOperand(0), getOperand(0));
} else if (getOpcode() == Instruction::Shl || getOpcode() ==Instruction::Shr){
- replaceAllUsesWith(getShift(getOpcode(), getOperand(0), getOperand(0)));
+ New = getShift(getOpcode(), getOperand(0), getOperand(0));
} else {
assert(getOpcode() == Instruction::GetElementPtr);
@@ -820,10 +830,12 @@
std::vector<Constant*> C;
for (unsigned i = 1, e = getNumOperands(); i != e; ++i)
C.push_back(cast<Constant>(getOperand(i)));
- replaceAllUsesWith(ConstantExpr::getGetElementPtr(getOperand(0),
- C));
+ New = ConstantExpr::getGetElementPtr(getOperand(0), C);
+ }
+ if (New != this) {
+ replaceAllUsesWith(New);
+ destroyConstant(); // This constant is now dead, destroy it.
}
- destroyConstant(); // This constant is now dead, destroy it.
}
More information about the llvm-commits
mailing list