aboutsummaryrefslogtreecommitdiff
path: root/lib/Bytecode
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-07-30 18:54:22 +0000
committerChris Lattner <sabre@nondot.org>2002-07-30 18:54:22 +0000
commite8e4605021141d689493132a9c7c6fce6294937f (patch)
tree0f0c6d598e711050201cc4079fb8b874214dc62c /lib/Bytecode
parent53b7f26150060c990c4b3431d340d52747c0b24c (diff)
Cleanup ConstantExpr handling:
* Correctly delete TypeHandles in AsmParser. In addition to not leaking memory, this prevents a bug that could have occurred when a type got resolved that the constexpr was using * Check for errors in the AsmParser instead of hitting assertion failures deep in the code * Simplify the interface to the ConstantExpr class, removing unneccesary parameters to the ::get* methods. * Rename the 'getelementptr' version of ConstantExpr::get to ConstantExpr::getGetElementPtr git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3160 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bytecode')
-rw-r--r--lib/Bytecode/Reader/ConstantReader.cpp44
1 files changed, 22 insertions, 22 deletions
diff --git a/lib/Bytecode/Reader/ConstantReader.cpp b/lib/Bytecode/Reader/ConstantReader.cpp
index 6e86997f22..921b875644 100644
--- a/lib/Bytecode/Reader/ConstantReader.cpp
+++ b/lib/Bytecode/Reader/ConstantReader.cpp
@@ -186,43 +186,43 @@ bool BytecodeParser::parseConstantValue(const uchar *&Buf, const uchar *EndBuf,
unsigned isExprNumArgs; // 0 if not expr; numArgs if is expr
if (read_vbr(Buf, EndBuf, isExprNumArgs)) return failure(true);
if (isExprNumArgs) {
- unsigned opCode;
- std::vector<Constant*> argVec;
- argVec.reserve(isExprNumArgs);
-
- if (read_vbr(Buf, EndBuf, opCode)) return failure(true);
-
+ // FIXME: Encoding of constant exprs could be much more compact!
+ unsigned Opcode;
+ std::vector<Constant*> ArgVec;
+ ArgVec.reserve(isExprNumArgs);
+ if (read_vbr(Buf, EndBuf, Opcode)) return failure(true);
+
// Read the slot number and types of each of the arguments
- for (unsigned i=0; i < isExprNumArgs; ++i) {
- unsigned argValSlot, argTypeSlot;
- if (read_vbr(Buf, EndBuf, argValSlot)) return failure(true);
- if (read_vbr(Buf, EndBuf, argTypeSlot)) return failure(true);
- const Type *argTy = getType(argTypeSlot);
- if (argTy == 0) return failure(true);
+ for (unsigned i = 0; i != isExprNumArgs; ++i) {
+ unsigned ArgValSlot, ArgTypeSlot;
+ if (read_vbr(Buf, EndBuf, ArgValSlot)) return failure(true);
+ if (read_vbr(Buf, EndBuf, ArgTypeSlot)) return failure(true);
+ const Type *ArgTy = getType(ArgTypeSlot);
+ if (ArgTy == 0) return failure(true);
- BCR_TRACE(4, "CE Arg " << i << ": Type: '" << argTy << "' slot: "
- << argValSlot << "\n");
+ BCR_TRACE(4, "CE Arg " << i << ": Type: '" << ArgTy << "' slot: "
+ << ArgValSlot << "\n");
// Get the arg value from its slot if it exists, otherwise a placeholder
- Value *Val = getValue(argTy, argValSlot, false);
+ Value *Val = getValue(ArgTy, ArgValSlot, false);
Constant *C;
if (Val) {
if (!(C = dyn_cast<Constant>(Val))) return failure(true);
BCR_TRACE(5, "Constant Found in ValueTable!\n");
} else { // Nope... find or create a forward ref. for it
- C = fwdRefs.GetFwdRefToConstant(argTy, argValSlot);
+ C = fwdRefs.GetFwdRefToConstant(ArgTy, ArgValSlot);
}
- argVec.push_back(C);
+ ArgVec.push_back(C);
}
// Construct a ConstantExpr of the appropriate kind
if (isExprNumArgs == 1) { // All one-operand expressions
- V = ConstantExpr::get(opCode, argVec[0], Ty);
- } else if (opCode == Instruction::GetElementPtr) { // GetElementPtr
- std::vector<Constant*> IdxList(argVec.begin()+1, argVec.end());
- V = ConstantExpr::get(opCode, argVec[0], IdxList, Ty);
+ V = ConstantExpr::get(Opcode, ArgVec[0], Ty);
+ } else if (Opcode == Instruction::GetElementPtr) { // GetElementPtr
+ std::vector<Constant*> IdxList(ArgVec.begin()+1, ArgVec.end());
+ V = ConstantExpr::getGetElementPtr(ArgVec[0], IdxList);
} else { // All other 2-operand expressions
- V = ConstantExpr::get(opCode, argVec[0], argVec[1], Ty);
+ V = ConstantExpr::get(Opcode, ArgVec[0], ArgVec[1]);
}
return false;
}