Bitcode: Fix reading and writing of ConstantDataVectors of halfs

In r254991 I allowed ConstantDataVectors to contain elements of
HalfTy, but I missed updating the bitcode reader and writer to handle
this, so now we crash if we try to emit bitcode on programs that have
constant vectors of half.

This fixes the issue and adds test coverage for reading and writing
constant sequences in bitcode.

llvm-svn: 256982
This commit is contained in:
Justin Bogner
2016-01-06 22:31:32 +00:00
parent 58a636ac06
commit a43eacbf9e
3 changed files with 47 additions and 23 deletions

View File

@@ -1630,19 +1630,10 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal,
if (isa<IntegerType>(EltTy)) {
for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
Record.push_back(CDS->getElementAsInteger(i));
} else if (EltTy->isFloatTy()) {
for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
union { float F; uint32_t I; };
F = CDS->getElementAsFloat(i);
Record.push_back(I);
}
} else {
assert(EltTy->isDoubleTy() && "Unknown ConstantData element type");
for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
union { double F; uint64_t I; };
F = CDS->getElementAsDouble(i);
Record.push_back(I);
}
for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
Record.push_back(
CDS->getElementAsAPFloat(i).bitcastToAPInt().getLimitedValue());
}
} else if (isa<ConstantArray>(C) || isa<ConstantStruct>(C) ||
isa<ConstantVector>(C)) {