diff options
author | NAKAMURA Takumi <geek4civic@gmail.com> | 2015-02-20 14:24:49 +0000 |
---|---|---|
committer | NAKAMURA Takumi <geek4civic@gmail.com> | 2015-02-20 14:24:49 +0000 |
commit | e86b9b76c5dea40881538fe32ea1e29a276ced7c (patch) | |
tree | ca56f09d53f4785eb83f31aad10359f0097a69f2 /llvm/lib/IR/Constants.cpp | |
parent | 6f66545ae61572d47576060cae77cdf5545c4529 (diff) | |
download | llvm-e86b9b76c5dea40881538fe32ea1e29a276ced7c.zip llvm-e86b9b76c5dea40881538fe32ea1e29a276ced7c.tar.gz llvm-e86b9b76c5dea40881538fe32ea1e29a276ced7c.tar.bz2 |
Constants.cpp: getElementAsAPFloat(): Don't handle constant value via host's float/double, just handle with APInt/APFloat.
x87 FPU didn't keep SNAN, but demoted to QNAN.
llvm-svn: 230013
Diffstat (limited to 'llvm/lib/IR/Constants.cpp')
-rw-r--r-- | llvm/lib/IR/Constants.cpp | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp index e87aa3d..1c93265 100644 --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -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)); } } |