[llvm-commits] CVS: llvm/lib/Bytecode/Reader/Reader.cpp

Chris Lattner lattner at cs.uiuc.edu
Tue Oct 22 19:53:01 PDT 2002


Changes in directory llvm/lib/Bytecode/Reader:

Reader.cpp updated: 1.39 -> 1.40

---
Log message:

  - 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.



---
Diffs of the changes:

Index: llvm/lib/Bytecode/Reader/Reader.cpp
diff -u llvm/lib/Bytecode/Reader/Reader.cpp:1.39 llvm/lib/Bytecode/Reader/Reader.cpp:1.40
--- llvm/lib/Bytecode/Reader/Reader.cpp:1.39	Tue Oct 22 18:55:24 2002
+++ llvm/lib/Bytecode/Reader/Reader.cpp	Tue Oct 22 19:51:54 2002
@@ -48,15 +48,14 @@
 }
 
 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 @@
 
   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 @@
       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();
 





More information about the llvm-commits mailing list