Constants.cpp: getElementAsAPFloat(): Don't handle constant value via host's float...
authorNAKAMURA Takumi <geek4civic@gmail.com>
Fri, 20 Feb 2015 14:24:49 +0000 (14:24 +0000)
committerNAKAMURA Takumi <geek4civic@gmail.com>
Fri, 20 Feb 2015 14:24:49 +0000 (14:24 +0000)
x87 FPU didn't keep SNAN, but demoted to QNAN.

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

lib/IR/Constants.cpp

index e87aa3d92ede492d5f81c878567f9c0641472485..1c93265c79df463ff68ff108372a2830ec86b52d 100644 (file)
@@ -2715,18 +2715,15 @@ 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: {
-      const float *FloatPrt = reinterpret_cast<const float *>(EltPtr);
-      return APFloat(*const_cast<float *>(FloatPrt));
-    }
-  case Type::DoubleTyID: {
-      const double *DoublePtr = reinterpret_cast<const double *>(EltPtr);
-      return APFloat(*const_cast<double *>(DoublePtr));
-    }
+  case Type::FloatTyID:
+    return APFloat(APFloat::IEEEsingle, APInt(32, EltVal));
+  case Type::DoubleTyID:
+    return APFloat(APFloat::IEEEdouble, APInt(64, EltVal));
   }
 }