diff --git a/lib/IR/Constants.cpp b/lib/IR/Constants.cpp index 1c93265c79d..0bf61a77ea2 100644 --- a/lib/IR/Constants.cpp +++ b/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(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(EltPtr); return APFloat(APFloat::IEEEsingle, APInt(32, EltVal)); - case Type::DoubleTyID: + } + case Type::DoubleTyID: { + auto EltVal = *reinterpret_cast(EltPtr); return APFloat(APFloat::IEEEdouble, APInt(64, EltVal)); } + } } /// getElementAsFloat - If this is an sequential container of floats, return