From: Chris Lattner Date: Sat, 22 Sep 2007 18:47:25 +0000 (+0000) Subject: further apfloat'ize the front-end, allowing codegen to pass X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c9bec4bfea9090a08dd83a7b213f0c8adf8d78ec;p=clang further apfloat'ize the front-end, allowing codegen to pass APFloat straight through to LLVM now. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42236 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/AST/Expr.cpp b/AST/Expr.cpp index e5a128247e..01c563bdc2 100644 --- a/AST/Expr.cpp +++ b/AST/Expr.cpp @@ -741,7 +741,7 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx, if (const FloatingLiteral *FL = dyn_cast(Operand)) { // FIXME: Evaluate this correctly! - Result = (int)FL->getValue(); + Result = (int)FL->getValueAsDouble(); break; } if (Loc) *Loc = Operand->getLocStart(); diff --git a/AST/StmtDumper.cpp b/AST/StmtDumper.cpp index 09909d8419..6f25e129a3 100644 --- a/AST/StmtDumper.cpp +++ b/AST/StmtDumper.cpp @@ -307,7 +307,7 @@ void StmtDumper::VisitIntegerLiteral(IntegerLiteral *Node) { } void StmtDumper::VisitFloatingLiteral(FloatingLiteral *Node) { DumpExpr(Node); - fprintf(F, " %f", Node->getValue()); + fprintf(F, " %f", Node->getValueAsDouble()); } void StmtDumper::VisitStringLiteral(StringLiteral *Str) { diff --git a/AST/StmtPrinter.cpp b/AST/StmtPrinter.cpp index 11dd2ef767..f878ca8137 100644 --- a/AST/StmtPrinter.cpp +++ b/AST/StmtPrinter.cpp @@ -408,7 +408,7 @@ void StmtPrinter::VisitIntegerLiteral(IntegerLiteral *Node) { } void StmtPrinter::VisitFloatingLiteral(FloatingLiteral *Node) { // FIXME: print value more precisely. - OS << Node->getValue(); + OS << Node->getValueAsDouble(); } void StmtPrinter::VisitImaginaryLiteral(ImaginaryLiteral *Node) { diff --git a/CodeGen/CGExprScalar.cpp b/CodeGen/CGExprScalar.cpp index 319ca82bf8..155cf3b313 100644 --- a/CodeGen/CGExprScalar.cpp +++ b/CodeGen/CGExprScalar.cpp @@ -93,13 +93,7 @@ public: return llvm::ConstantInt::get(E->getValue()); } Value *VisitFloatingLiteral(const FloatingLiteral *E) { - double V = E->getValue(); - // FIXME: Change this when FloatingLiteral uses an APFloat internally. - const llvm::Type *Ty = ConvertType(E->getType()); - if (Ty == llvm::Type::FloatTy) - return llvm::ConstantFP::get(Ty, llvm::APFloat((float)V)); - assert(Ty == llvm::Type::DoubleTy && "Unknown float type!"); - return llvm::ConstantFP::get(Ty, llvm::APFloat((double)V)); + return llvm::ConstantFP::get(ConvertType(E->getType()), E->getValue()); } Value *VisitCharacterLiteral(const CharacterLiteral *E) { return llvm::ConstantInt::get(ConvertType(E->getType()), E->getValue()); diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 54228696ef..94c02aa3e9 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -223,7 +223,9 @@ public: FloatingLiteral(const llvm::APFloat &V, QualType Type, SourceLocation L) : Expr(FloatingLiteralClass, Type), Value(V), Loc(L) {} - float getValue() const { + const llvm::APFloat &getValue() const { return Value; } + + double getValueAsDouble() const { if (cast(getType())->getKind() == BuiltinType::Float) return Value.convertToFloat(); else