1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 19:23:23 +01:00

Constants.cpp: Only read 32 bits for float.

Otherwise we'll discard the wrong half of a uint64_t on big-endian systems.

llvm-svn: 230016
This commit is contained in:
Benjamin Kramer 2015-02-20 15:11:55 +00:00
parent 5d88ffd396
commit 9de6bbe4af

View File

@ -2715,16 +2715,19 @@ uint64_t ConstantDataSequential::getElementAsInteger(unsigned Elt) const {
/// type, return the specified element as an APFloat.
APFloat ConstantDataSequential::getElementAsAPFloat(unsigned Elt) const {
const char *EltPtr = getElementPointer(Elt);
auto EltVal = *reinterpret_cast<const uint64_t *>(EltPtr);
switch (getElementType()->getTypeID()) {
default:
llvm_unreachable("Accessor can only be used when element is float/double!");
case Type::FloatTyID:
case Type::FloatTyID: {
auto EltVal = *reinterpret_cast<const uint32_t *>(EltPtr);
return APFloat(APFloat::IEEEsingle, APInt(32, EltVal));
case Type::DoubleTyID:
}
case Type::DoubleTyID: {
auto EltVal = *reinterpret_cast<const uint64_t *>(EltPtr);
return APFloat(APFloat::IEEEdouble, APInt(64, EltVal));
}
}
}
/// getElementAsFloat - If this is an sequential container of floats, return