diff options
author | Chris Lattner <sabre@nondot.org> | 2002-10-23 00:51:54 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2002-10-23 00:51:54 +0000 |
commit | 8cdc6b726a79f4406f9bb067942b582052c07018 (patch) | |
tree | 7be4a4449d766853fdc28bb7740a623f0c14f1ac /lib/Bytecode | |
parent | 5dfab9ec22bcae02a7120823cac085d02661c55f (diff) |
- Fix a really nasty bug in the bytecode reader that caused it to fail
reading bytecode files with > 255 types in them, but only when optimization
is enabled. This was caused by GCC shrinking an enum to a single byte
instead of a whole word.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4266 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bytecode')
-rw-r--r-- | lib/Bytecode/Reader/Reader.cpp | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp index 23af02e516..0f9889c4c8 100644 --- a/lib/Bytecode/Reader/Reader.cpp +++ b/lib/Bytecode/Reader/Reader.cpp @@ -48,15 +48,14 @@ bool BytecodeParser::getTypeSlot(const Type *Ty, unsigned &Slot) { } const Type *BytecodeParser::getType(unsigned ID) { - const Type *T = Type::getPrimitiveType((Type::PrimitiveID)ID); - if (T) return T; + if (ID < Type::NumPrimitiveIDs) { + const Type *T = Type::getPrimitiveType((Type::PrimitiveID)ID); + if (T) return T; + } //cerr << "Looking up Type ID: " << ID << "\n"; - - const Value *D = getValue(Type::TypeTy, ID, false); - if (D == 0) return 0; - - return cast<Type>(D); + const Value *V = getValue(Type::TypeTy, ID, false); + return cast_or_null<Type>(V); } int BytecodeParser::insertValue(Value *Val, std::vector<ValueList> &ValueTab) { @@ -82,8 +81,10 @@ Value *BytecodeParser::getValue(const Type *Ty, unsigned oNum, bool Create) { if (type == Type::TypeTyID) { // The 'type' plane has implicit values assert(Create == false); - const Type *T = Type::getPrimitiveType((Type::PrimitiveID)Num); - if (T) return (Value*)T; // Asked for a primitive type... + if (Num < Type::NumPrimitiveIDs) { + const Type *T = Type::getPrimitiveType((Type::PrimitiveID)Num); + if (T) return (Value*)T; // Asked for a primitive type... + } // Otherwise, derived types need offset... Num -= FirstDerivedTyID; @@ -452,7 +453,7 @@ bool BytecodeParser::ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End, Error = "Function not ptr to func type! Ty = " + Ty->getDescription(); return true; } - + // We create methods by passing the underlying FunctionType to create... Ty = cast<PointerType>(Ty)->getElementType(); |