summaryrefslogtreecommitdiff
path: root/lib/Bytecode
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2001-10-21 00:14:44 +0000
committerChris Lattner <sabre@nondot.org>2001-10-21 00:14:44 +0000
commit5ab1f877864c7ab9604321ce50091d101baca203 (patch)
treeb42cfedd0df94684edd18e52c061fd271af1cf04 /lib/Bytecode
parent2827d528684be221c0d6cf65d2e266e903cf61de (diff)
downloadllvm-5ab1f877864c7ab9604321ce50091d101baca203.tar.gz
llvm-5ab1f877864c7ab9604321ce50091d101baca203.tar.bz2
llvm-5ab1f877864c7ab9604321ce50091d101baca203.tar.xz
Fix problem with a cast instruction that must be expanded to type 0
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@929 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bytecode')
-rw-r--r--lib/Bytecode/Reader/InstructionReader.cpp10
-rw-r--r--lib/Bytecode/Writer/InstructionWriter.cpp11
2 files changed, 16 insertions, 5 deletions
diff --git a/lib/Bytecode/Reader/InstructionReader.cpp b/lib/Bytecode/Reader/InstructionReader.cpp
index 58f2656559..1f4aa68f4a 100644
--- a/lib/Bytecode/Reader/InstructionReader.cpp
+++ b/lib/Bytecode/Reader/InstructionReader.cpp
@@ -48,6 +48,7 @@ bool BytecodeParser::ParseRawInst(const uchar *&Buf, const uchar *EndBuf,
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) {
@@ -109,10 +110,13 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
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) {
diff --git a/lib/Bytecode/Writer/InstructionWriter.cpp b/lib/Bytecode/Writer/InstructionWriter.cpp
index c972a7cf79..c6a32ed51f 100644
--- a/lib/Bytecode/Writer/InstructionWriter.cpp
+++ b/lib/Bytecode/Writer/InstructionWriter.cpp
@@ -34,13 +34,20 @@ static void outputInstructionFormat0(const Instruction *I,
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!
}
@@ -210,7 +217,7 @@ void BytecodeWriter::processInstruction(const Instruction *I) {
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());