]> granicus.if.org Git - clang/commitdiff
work around bugs and missing features in apfloat.
authorChris Lattner <sabre@nondot.org>
Sat, 22 Sep 2007 18:38:30 +0000 (18:38 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 22 Sep 2007 18:38:30 +0000 (18:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42235 91177308-0d34-0410-b5e6-96231b3b80d8

Basic/TargetInfo.cpp
Lex/LiteralSupport.cpp
include/clang/AST/Expr.h

index 2b0af7ed24c96cfa1f01f9196ddf269df02e854c..2c476b8627cf825cdee2d1437a0b6f2fe16307d2 100644 (file)
@@ -42,8 +42,10 @@ void TargetInfo::getDoubleInfo(uint64_t &Size, unsigned &Align,
 void TargetInfo::getLongDoubleInfo(uint64_t &Size, unsigned &Align,
                                    const llvm::fltSemantics *&Format,
                                    SourceLocation Loc) {
-  Size = 80; Align = 32;  // FIXME: implement correctly.
-  Format = &llvm::APFloat::x87DoubleExtended;
+  Size = Align = 64;  // FIXME: implement correctly.
+  Format = &llvm::APFloat::IEEEdouble;
+  //Size = 80; Align = 32;  // FIXME: implement correctly.
+  //Format = &llvm::APFloat::x87DoubleExtended;
 }
 
 
index 3449c2769af4cf5165b5f66c1b435960cd189a04..ae4c1a8fdeb38cb4abda2a8ad7c98938326794b0 100644 (file)
@@ -409,13 +409,20 @@ bool NumericLiteralParser::GetIntegerValue(llvm::APInt &Val) {
   return OverflowOccurred;
 }
 
-// GetFloatValue - Poor man's floatvalue (FIXME).
 llvm::APFloat NumericLiteralParser::
 GetFloatValue(const llvm::fltSemantics &Format) {
   char floatChars[256];
   strncpy(floatChars, ThisTokBegin, ThisTokEnd-ThisTokBegin);
   floatChars[ThisTokEnd-ThisTokBegin] = '\0';
+#if 0
+  // This doesn't work yet.
   return llvm::APFloat(Format, floatChars);
+#else
+  // FIXME: this is horrible!
+  llvm::APFloat V(strtod(floatChars, 0));
+  V.convert(Format, llvm::APFloat::rmTowardZero);
+  return V;
+#endif
 }
 
 void NumericLiteralParser::Diag(SourceLocation Loc, unsigned DiagID, 
index 08b2b6c03674305d1ae5f7b4ed5fd38c636e38bd..54228696eff31b8e8f1a408bd1e5862ad267b537 100644 (file)
@@ -223,7 +223,12 @@ public:
   FloatingLiteral(const llvm::APFloat &V, QualType Type, SourceLocation L)
     : Expr(FloatingLiteralClass, Type), Value(V), Loc(L) {} 
 
-  float getValue() const { return Value.convertToDouble(); }
+  float getValue() const { 
+    if (cast<BuiltinType>(getType())->getKind() == BuiltinType::Float)
+      return Value.convertToFloat();
+    else
+      return Value.convertToDouble();
+  }
   
   virtual SourceRange getSourceRange() const { return SourceRange(Loc); }