summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Bytecode/Reader
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-04-07 05:00:02 +0000
committerChris Lattner <sabre@nondot.org>2006-04-07 05:00:02 +0000
commit92b1a570101f353857a5c79ee21a2a2a10715982 (patch)
tree8dcfd8b71afc51854a64c05c220d471729700642 /llvm/lib/Bytecode/Reader
parente4f9d7b23cbf6170b1e2d00b8511174ecf6a7d7b (diff)
downloadbcm5719-llvm-92b1a570101f353857a5c79ee21a2a2a10715982.tar.gz
bcm5719-llvm-92b1a570101f353857a5c79ee21a2a2a10715982.zip
We have an assertion that checks that we do not encode null values into the
.bc file if they are supposed to be implicit. This is cool, except that it checked *after* constant expr folding: improving constant expr folding could cause the .bc reader to assert out on old .bc files. Move the check so that it checks all simple constants, but no constantexprs. llvm-svn: 27480
Diffstat (limited to 'llvm/lib/Bytecode/Reader')
-rw-r--r--llvm/lib/Bytecode/Reader/Reader.cpp60
1 files changed, 32 insertions, 28 deletions
diff --git a/llvm/lib/Bytecode/Reader/Reader.cpp b/llvm/lib/Bytecode/Reader/Reader.cpp
index 61b194ab39a..9f064468cad 100644
--- a/llvm/lib/Bytecode/Reader/Reader.cpp
+++ b/llvm/lib/Bytecode/Reader/Reader.cpp
@@ -544,10 +544,6 @@ Constant* BytecodeReader::getConstantValue(unsigned TypeSlot, unsigned Slot) {
/// or FunctionValues data members of this class.
unsigned BytecodeReader::insertValue(Value *Val, unsigned type,
ValueTable &ValueTab) {
- assert((!isa<Constant>(Val) || !cast<Constant>(Val)->isNullValue()) ||
- !hasImplicitNull(type) &&
- "Cannot read null values from bytecode!");
-
if (ValueTab.size() <= type)
ValueTab.resize(type+1);
@@ -1506,14 +1502,15 @@ Value *BytecodeReader::ParseConstantPoolValue(unsigned TypeID) {
// Ok, not an ConstantExpr. We now know how to read the given type...
const Type *Ty = getType(TypeID);
+ Constant *Result = 0;
switch (Ty->getTypeID()) {
case Type::BoolTyID: {
unsigned Val = read_vbr_uint();
if (Val != 0 && Val != 1)
error("Invalid boolean value read.");
- Constant* Result = ConstantBool::get(Val == 1);
+ Result = ConstantBool::get(Val == 1);
if (Handler) Handler->handleConstantValue(Result);
- return Result;
+ break;
}
case Type::UByteTyID: // Unsigned integer types...
@@ -1522,43 +1519,42 @@ Value *BytecodeReader::ParseConstantPoolValue(unsigned TypeID) {
unsigned Val = read_vbr_uint();
if (!ConstantUInt::isValueValidForType(Ty, Val))
error("Invalid unsigned byte/short/int read.");
- Constant* Result = ConstantUInt::get(Ty, Val);
+ Result = ConstantUInt::get(Ty, Val);
if (Handler) Handler->handleConstantValue(Result);
- return Result;
+ break;
}
- case Type::ULongTyID: {
- Constant* Result = ConstantUInt::get(Ty, read_vbr_uint64());
+ case Type::ULongTyID:
+ Result = ConstantUInt::get(Ty, read_vbr_uint64());
if (Handler) Handler->handleConstantValue(Result);
- return Result;
- }
-
+ break;
+
case Type::SByteTyID: // Signed integer types...
case Type::ShortTyID:
- case Type::IntTyID: {
- case Type::LongTyID:
+ case Type::IntTyID:
+ case Type::LongTyID: {
int64_t Val = read_vbr_int64();
if (!ConstantSInt::isValueValidForType(Ty, Val))
error("Invalid signed byte/short/int/long read.");
- Constant* Result = ConstantSInt::get(Ty, Val);
+ Result = ConstantSInt::get(Ty, Val);
if (Handler) Handler->handleConstantValue(Result);
- return Result;
+ break;
}
case Type::FloatTyID: {
float Val;
read_float(Val);
- Constant* Result = ConstantFP::get(Ty, Val);
+ Result = ConstantFP::get(Ty, Val);
if (Handler) Handler->handleConstantValue(Result);
- return Result;
+ break;
}
case Type::DoubleTyID: {
double Val;
read_double(Val);
- Constant* Result = ConstantFP::get(Ty, Val);
+ Result = ConstantFP::get(Ty, Val);
if (Handler) Handler->handleConstantValue(Result);
- return Result;
+ break;
}
case Type::ArrayTyID: {
@@ -1570,9 +1566,9 @@ Value *BytecodeReader::ParseConstantPoolValue(unsigned TypeID) {
while (NumElements--) // Read all of the elements of the constant.
Elements.push_back(getConstantValue(TypeSlot,
read_vbr_uint()));
- Constant* Result = ConstantArray::get(AT, Elements);
+ Result = ConstantArray::get(AT, Elements);
if (Handler) Handler->handleConstantArray(AT, Elements, TypeSlot, Result);
- return Result;
+ break;
}
case Type::StructTyID: {
@@ -1584,9 +1580,9 @@ Value *BytecodeReader::ParseConstantPoolValue(unsigned TypeID) {
Elements.push_back(getConstantValue(ST->getElementType(i),
read_vbr_uint()));
- Constant* Result = ConstantStruct::get(ST, Elements);
+ Result = ConstantStruct::get(ST, Elements);
if (Handler) Handler->handleConstantStruct(ST, Elements, Result);
- return Result;
+ break;
}
case Type::PackedTyID: {
@@ -1598,9 +1594,9 @@ Value *BytecodeReader::ParseConstantPoolValue(unsigned TypeID) {
while (NumElements--) // Read all of the elements of the constant.
Elements.push_back(getConstantValue(TypeSlot,
read_vbr_uint()));
- Constant* Result = ConstantPacked::get(PT, Elements);
+ Result = ConstantPacked::get(PT, Elements);
if (Handler) Handler->handleConstantPacked(PT, Elements, TypeSlot, Result);
- return Result;
+ break;
}
case Type::PointerTyID: { // ConstantPointerRef value (backwards compat).
@@ -1624,7 +1620,15 @@ Value *BytecodeReader::ParseConstantPoolValue(unsigned TypeID) {
Ty->getDescription());
break;
}
- return 0;
+
+ // Check that we didn't read a null constant if they are implicit for this
+ // type plane. Do not do this check for constantexprs, as they may be folded
+ // to a null value in a way that isn't predicted when a .bc file is initially
+ // produced.
+ assert((!isa<Constant>(Result) || !cast<Constant>(Result)->isNullValue()) ||
+ !hasImplicitNull(TypeID) &&
+ "Cannot read null values from bytecode!");
+ return Result;
}
/// Resolve references for constants. This function resolves the forward
OpenPOWER on IntegriCloud