From 0a29cb045444c13160e90fe7942a9d7c720185ed Mon Sep 17 00:00:00 2001 From: Tim Northover Date: Tue, 22 Jan 2013 09:46:31 +0000 Subject: Make APFloat constructor require explicit semantics. Previously we tried to infer it from the bit width size, with an added IsIEEE argument for the PPC/IEEE 128-bit case, which had a default value. This default value allowed bugs to creep in, where it was inappropriate. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@173138 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/ExecutionEngine/ExecutionEngine.cpp | 19 ++++++++++++------- lib/ExecutionEngine/JIT/JIT.cpp | 3 ++- 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'lib/ExecutionEngine') diff --git a/lib/ExecutionEngine/ExecutionEngine.cpp b/lib/ExecutionEngine/ExecutionEngine.cpp index 6f71ffb2fa..3d59d251a0 100644 --- a/lib/ExecutionEngine/ExecutionEngine.cpp +++ b/lib/ExecutionEngine/ExecutionEngine.cpp @@ -632,7 +632,7 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) { else if (Op0->getType()->isDoubleTy()) GV.IntVal = APIntOps::RoundDoubleToAPInt(GV.DoubleVal, BitWidth); else if (Op0->getType()->isX86_FP80Ty()) { - APFloat apf = APFloat(GV.IntVal); + APFloat apf = APFloat(APFloat::x87DoubleExtended, GV.IntVal); uint64_t v; bool ignored; (void)apf.convertToInteger(&v, BitWidth, @@ -751,27 +751,32 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) { case Type::X86_FP80TyID: case Type::PPC_FP128TyID: case Type::FP128TyID: { - APFloat apfLHS = APFloat(LHS.IntVal); + const fltSemantics &Sem = CE->getOperand(0)->getType()->getFltSemantics(); + APFloat apfLHS = APFloat(Sem, LHS.IntVal); switch (CE->getOpcode()) { default: llvm_unreachable("Invalid long double opcode"); case Instruction::FAdd: - apfLHS.add(APFloat(RHS.IntVal), APFloat::rmNearestTiesToEven); + apfLHS.add(APFloat(Sem, RHS.IntVal), APFloat::rmNearestTiesToEven); GV.IntVal = apfLHS.bitcastToAPInt(); break; case Instruction::FSub: - apfLHS.subtract(APFloat(RHS.IntVal), APFloat::rmNearestTiesToEven); + apfLHS.subtract(APFloat(Sem, RHS.IntVal), + APFloat::rmNearestTiesToEven); GV.IntVal = apfLHS.bitcastToAPInt(); break; case Instruction::FMul: - apfLHS.multiply(APFloat(RHS.IntVal), APFloat::rmNearestTiesToEven); + apfLHS.multiply(APFloat(Sem, RHS.IntVal), + APFloat::rmNearestTiesToEven); GV.IntVal = apfLHS.bitcastToAPInt(); break; case Instruction::FDiv: - apfLHS.divide(APFloat(RHS.IntVal), APFloat::rmNearestTiesToEven); + apfLHS.divide(APFloat(Sem, RHS.IntVal), + APFloat::rmNearestTiesToEven); GV.IntVal = apfLHS.bitcastToAPInt(); break; case Instruction::FRem: - apfLHS.mod(APFloat(RHS.IntVal), APFloat::rmNearestTiesToEven); + apfLHS.mod(APFloat(Sem, RHS.IntVal), + APFloat::rmNearestTiesToEven); GV.IntVal = apfLHS.bitcastToAPInt(); break; } diff --git a/lib/ExecutionEngine/JIT/JIT.cpp b/lib/ExecutionEngine/JIT/JIT.cpp index 103c0c0d1b..53ea0a2600 100644 --- a/lib/ExecutionEngine/JIT/JIT.cpp +++ b/lib/ExecutionEngine/JIT/JIT.cpp @@ -522,7 +522,8 @@ GenericValue JIT::runFunction(Function *F, case Type::PPC_FP128TyID: case Type::X86_FP80TyID: case Type::FP128TyID: - C = ConstantFP::get(F->getContext(), APFloat(AV.IntVal)); + C = ConstantFP::get(F->getContext(), APFloat(ArgTy->getFltSemantics(), + AV.IntVal)); break; case Type::PointerTyID: void *ArgPtr = GVTOP(AV); -- cgit v1.2.3