From abec474236601d7c10469a212decd010727ba060 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 17 Oct 2008 06:11:48 +0000 Subject: [PATCH] add some simple hacky long double support for the CBE. This should work for intel long double, but ppc long double aborts in convert. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@57672 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/CBackend/CBackend.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp index 7ec649d0c52..72bc920b032 100644 --- a/lib/Target/CBackend/CBackend.cpp +++ b/lib/Target/CBackend/CBackend.cpp @@ -1129,11 +1129,21 @@ void CWriter::printConstant(Constant *CPV, bool Static) { "long double") << "*)&FPConstant" << I->second << ')'; } else { - assert(FPC->getType() == Type::FloatTy || - FPC->getType() == Type::DoubleTy); - double V = FPC->getType() == Type::FloatTy ? - FPC->getValueAPF().convertToFloat() : - FPC->getValueAPF().convertToDouble(); + double V; + if (FPC->getType() == Type::FloatTy) + V = FPC->getValueAPF().convertToFloat(); + else if (FPC->getType() == Type::DoubleTy) + V = FPC->getValueAPF().convertToDouble(); + else { + // Long double. Convert the number to double, discarding precision. + // This is not awesome, but it at least makes the CBE output somewhat + // useful. + APFloat Tmp = FPC->getValueAPF(); + bool LosesInfo; + Tmp.convert(APFloat::IEEEdouble, APFloat::rmTowardZero, &LosesInfo); + V = Tmp.convertToDouble(); + } + if (IsNAN(V)) { // The value is NaN