[llvm] r230016 - Constants.cpp: Only read 32 bits for float.
Benjamin Kramer
benny.kra at googlemail.com
Fri Feb 20 07:11:56 PST 2015
Author: d0k
Date: Fri Feb 20 09:11:55 2015
New Revision: 230016
URL: http://llvm.org/viewvc/llvm-project?rev=230016&view=rev
Log:
Constants.cpp: Only read 32 bits for float.
Otherwise we'll discard the wrong half of a uint64_t on big-endian systems.
Modified:
llvm/trunk/lib/IR/Constants.cpp
Modified: llvm/trunk/lib/IR/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Constants.cpp?rev=230016&r1=230015&r2=230016&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Constants.cpp (original)
+++ llvm/trunk/lib/IR/Constants.cpp Fri Feb 20 09:11:55 2015
@@ -2715,16 +2715,19 @@ uint64_t ConstantDataSequential::getElem
/// 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
More information about the llvm-commits
mailing list