diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2015-02-20 15:11:55 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2015-02-20 15:11:55 +0000 |
commit | 7af984b710721bbcb4a44b8568b1b1d02d1c1f63 (patch) | |
tree | 1925424e6168684bff9d47cee6c6ccd57b9086d7 /llvm/lib/IR/Constants.cpp | |
parent | 7675f06c01bd1b394272be50d63d6bcb315e4884 (diff) | |
download | bcm5719-llvm-7af984b710721bbcb4a44b8568b1b1d02d1c1f63.tar.gz bcm5719-llvm-7af984b710721bbcb4a44b8568b1b1d02d1c1f63.zip |
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
Diffstat (limited to 'llvm/lib/IR/Constants.cpp')
-rw-r--r-- | llvm/lib/IR/Constants.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp index 1c93265c79d..0bf61a77ea2 100644 --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -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 |