work around bugs and missing features in apfloat.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42235 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Basic/TargetInfo.cpp b/Basic/TargetInfo.cpp
index 2b0af7e..2c476b8 100644
--- a/Basic/TargetInfo.cpp
+++ b/Basic/TargetInfo.cpp
@@ -42,8 +42,10 @@
 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;
 }
 
 
diff --git a/Lex/LiteralSupport.cpp b/Lex/LiteralSupport.cpp
index 3449c27..ae4c1a8 100644
--- a/Lex/LiteralSupport.cpp
+++ b/Lex/LiteralSupport.cpp
@@ -409,13 +409,20 @@
   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, 
diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h
index 08b2b6c..5422869 100644
--- a/include/clang/AST/Expr.h
+++ b/include/clang/AST/Expr.h
@@ -223,7 +223,12 @@
   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); }