Constants.cpp: Only read 32 bits for float.
authorBenjamin Kramer <benny.kra@googlemail.com>
Fri, 20 Feb 2015 15:11:55 +0000 (15:11 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Fri, 20 Feb 2015 15:11:55 +0000 (15:11 +0000)
Otherwise we'll discard the wrong half of a uint64_t on big-endian systems.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@230016 91177308-0d34-0410-b5e6-96231b3b80d8

lib/IR/Constants.cpp

index 1c93265c79df463ff68ff108372a2830ec86b52d..0bf61a77ea220b758fe9e4926b8dc1861fbb86d6 100644 (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