if (read_vbr(Buf, EndBuf, Result.Opcode)) return failure(true);
if (read_vbr(Buf, EndBuf, Typ)) return failure(true);
Result.Ty = getType(Typ);
+ if (Result.Ty == 0) return failure(true);
if (read_vbr(Buf, EndBuf, Result.NumOperands)) return failure(true);
switch (Result.NumOperands) {
Value *V;
switch (Raw.Opcode) {
- case Instruction::Cast:
- Res = new CastInst(getValue(Raw.Ty, Raw.Arg1), getType(Raw.Arg2));
+ case Instruction::Cast: {
+ V = getValue(Raw.Ty, Raw.Arg1);
+ const Type *Ty = getType(Raw.Arg2);
+ if (V == 0 || Ty == 0) { cerr << "Invalid cast!\n"; return true; }
+ Res = new CastInst(V, Ty);
return false;
-
+ }
case Instruction::PHINode: {
PHINode *PN = new PHINode(Raw.Ty);
switch (Raw.NumOperands) {
output_vbr(Type, Out); // Result type
unsigned NumArgs = I->getNumOperands();
- output_vbr(NumArgs, Out);
+ output_vbr(NumArgs + isa<CastInst>(I), Out);
for (unsigned i = 0; i < NumArgs; ++i) {
int Slot = Table.getValSlot(I->getOperand(i));
assert(Slot >= 0 && "No slot number for value!?!?");
output_vbr((unsigned)Slot, Out);
}
+
+ if (isa<CastInst>(I)) {
+ int Slot = Table.getValSlot(I->getType());
+ assert(Slot != -1 && "Cast return type unknown?");
+ output_vbr((unsigned)Slot, Out);
+ }
+
align32(Out); // We must maintain correct alignment!
}
if (Slot > MaxOpSlot) MaxOpSlot = Slot;
// Handle the special case for cast...
- if (I->getOpcode() == Instruction::Cast) {
+ if (isa<CastInst>(I)) {
// Cast has to encode the destination type as the second argument in the
// packet, or else we won't know what type to cast to!
Slots[1] = Table.getValSlot(I->getType());