]> granicus.if.org Git - clang/commitdiff
Add field IsIEEE in FloatingLiteral to distinguish between different 128-bit
authorAkira Hatanaka <ahatanaka@mips.com>
Tue, 10 Jan 2012 22:40:09 +0000 (22:40 +0000)
committerAkira Hatanaka <ahatanaka@mips.com>
Tue, 10 Jan 2012 22:40:09 +0000 (22:40 +0000)
floating point formats.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147887 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Expr.h
lib/AST/Expr.cpp
test/CodeGen/mips64-f128-literal.c [new file with mode: 0644]

index 9eff18b714113155ea87e55a9ffebf842b9c17eb..14c94e7ca86cd6156200f5ecea05d61183522e0c 100644 (file)
@@ -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);
   }
index bbf54112c8507c8a7ef0688897f56a0f91cf6beb..f87d60f7fbee487b9f37b4ac5fc5f87089d9fdcf 100644 (file)
@@ -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 (file)
index 0000000..2284b26
--- /dev/null
@@ -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;
+}