From 178723a6876e3f310dd1da56a6db63f778cb5ea8 Mon Sep 17 00:00:00 2001 From: Tim Northover Date: Tue, 22 Jan 2013 09:46:51 +0000 Subject: Switch to APFloat constructor taking fltSemantics. This change also makes the serialisation store the required semantics, fixing an issue where PPC128 was always assumed when re-reading a 128-bit value. llvm-svn: 173139 --- clang/lib/AST/Expr.cpp | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) (limited to 'clang/lib/AST/Expr.cpp') diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index e3ff29d2d0f..6888c46ae4f 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -646,16 +646,14 @@ FloatingLiteral::FloatingLiteral(ASTContext &C, const llvm::APFloat &V, bool isexact, QualType Type, SourceLocation L) : Expr(FloatingLiteralClass, Type, VK_RValue, OK_Ordinary, false, false, false, false), Loc(L) { - FloatingLiteralBits.IsIEEE = - &C.getTargetInfo().getLongDoubleFormat() == &llvm::APFloat::IEEEquad; + setSemantics(V.getSemantics()); FloatingLiteralBits.IsExact = isexact; setValue(C, V); } FloatingLiteral::FloatingLiteral(ASTContext &C, EmptyShell Empty) : Expr(FloatingLiteralClass, Empty) { - FloatingLiteralBits.IsIEEE = - &C.getTargetInfo().getLongDoubleFormat() == &llvm::APFloat::IEEEquad; + setRawSemantics(IEEEhalf); FloatingLiteralBits.IsExact = false; } @@ -670,6 +668,41 @@ FloatingLiteral::Create(ASTContext &C, EmptyShell Empty) { return new (C) FloatingLiteral(C, Empty); } +const llvm::fltSemantics &FloatingLiteral::getSemantics() const { + switch(FloatingLiteralBits.Semantics) { + case IEEEhalf: + return llvm::APFloat::IEEEhalf; + case IEEEsingle: + return llvm::APFloat::IEEEsingle; + case IEEEdouble: + return llvm::APFloat::IEEEdouble; + case x87DoubleExtended: + return llvm::APFloat::x87DoubleExtended; + case IEEEquad: + return llvm::APFloat::IEEEquad; + case PPCDoubleDouble: + return llvm::APFloat::PPCDoubleDouble; + } + llvm_unreachable("Unrecognised floating semantics"); +} + +void FloatingLiteral::setSemantics(const llvm::fltSemantics &Sem) { + if (&Sem == &llvm::APFloat::IEEEhalf) + FloatingLiteralBits.Semantics = IEEEhalf; + else if (&Sem == &llvm::APFloat::IEEEsingle) + FloatingLiteralBits.Semantics = IEEEsingle; + else if (&Sem == &llvm::APFloat::IEEEdouble) + FloatingLiteralBits.Semantics = IEEEdouble; + else if (&Sem == &llvm::APFloat::x87DoubleExtended) + FloatingLiteralBits.Semantics = x87DoubleExtended; + else if (&Sem == &llvm::APFloat::IEEEquad) + FloatingLiteralBits.Semantics = IEEEquad; + else if (&Sem == &llvm::APFloat::PPCDoubleDouble) + FloatingLiteralBits.Semantics = PPCDoubleDouble; + else + llvm_unreachable("Unknown floating semantics"); +} + /// getValueAsApproximateDouble - This returns the value as an inaccurate /// double. Note that this may cause loss of precision, but is useful for /// debugging dumps, etc. -- cgit v1.2.3