diff options
-rw-r--r-- | include/clang/AST/Expr.h | 17 | ||||
-rw-r--r-- | lib/AST/Expr.cpp | 2 | ||||
-rw-r--r-- | test/CodeGen/mips64-f128-literal.c | 9 |
3 files changed, 23 insertions, 5 deletions
diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 9eff18b714..14c94e7ca8 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -22,6 +22,7 @@ #include "clang/AST/ASTVector.h" #include "clang/AST/TemplateBase.h" #include "clang/AST/UsuallyTinyPtrVector.h" +#include "clang/Basic/TargetInfo.h" #include "clang/Basic/TypeTraits.h" #include "llvm/ADT/APSInt.h" #include "llvm/ADT/APFloat.h" @@ -1063,7 +1064,9 @@ public: class APFloatStorage : public APNumericStorage { public: - llvm::APFloat getValue() const { return llvm::APFloat(getIntValue()); } + llvm::APFloat getValue(bool IsIEEE) const { + return llvm::APFloat(getIntValue(), IsIEEE); + } void setValue(ASTContext &C, const llvm::APFloat &Val) { setIntValue(C, Val.bitcastToAPInt()); } @@ -1165,6 +1168,7 @@ public: class FloatingLiteral : public Expr { APFloatStorage Num; + bool IsIEEE : 1; // Distinguishes between PPC128 and IEEE128. bool IsExact : 1; SourceLocation Loc; @@ -1172,20 +1176,25 @@ class FloatingLiteral : public Expr { QualType Type, SourceLocation L) : Expr(FloatingLiteralClass, Type, VK_RValue, OK_Ordinary, false, false, false, false), + IsIEEE(&C.getTargetInfo().getLongDoubleFormat() == + &llvm::APFloat::IEEEquad), IsExact(isexact), Loc(L) { setValue(C, V); } /// \brief Construct an empty floating-point literal. - explicit FloatingLiteral(EmptyShell Empty) - : Expr(FloatingLiteralClass, Empty), IsExact(false) { } + explicit FloatingLiteral(ASTContext &C, EmptyShell Empty) + : Expr(FloatingLiteralClass, Empty), + IsIEEE(&C.getTargetInfo().getLongDoubleFormat() == + &llvm::APFloat::IEEEquad), + IsExact(false) { } public: static FloatingLiteral *Create(ASTContext &C, const llvm::APFloat &V, bool isexact, QualType Type, SourceLocation L); static FloatingLiteral *Create(ASTContext &C, EmptyShell Empty); - llvm::APFloat getValue() const { return Num.getValue(); } + llvm::APFloat getValue() const { return Num.getValue(IsIEEE); } void setValue(ASTContext &C, const llvm::APFloat &Val) { Num.setValue(C, Val); } diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index bbf54112c8..f87d60f7fb 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -476,7 +476,7 @@ FloatingLiteral::Create(ASTContext &C, const llvm::APFloat &V, FloatingLiteral * FloatingLiteral::Create(ASTContext &C, EmptyShell Empty) { - return new (C) FloatingLiteral(Empty); + return new (C) FloatingLiteral(C, Empty); } /// getValueAsApproximateDouble - This returns the value as an inaccurate diff --git a/test/CodeGen/mips64-f128-literal.c b/test/CodeGen/mips64-f128-literal.c new file mode 100644 index 0000000000..2284b2663a --- /dev/null +++ b/test/CodeGen/mips64-f128-literal.c @@ -0,0 +1,9 @@ +// RUN: %clang -ccc-host-triple mips64el-unknown-linux -ccc-clang-archs mips64el -O3 -S -mabi=n64 -o - -emit-llvm %s | FileCheck %s + +typedef long double LD; + +// CHECK: ret fp128 + +LD foo0() { + return 2.625L; +} |