diff options
-rw-r--r-- | AST/Expr.cpp | 2 | ||||
-rw-r--r-- | AST/StmtDumper.cpp | 2 | ||||
-rw-r--r-- | AST/StmtPrinter.cpp | 2 | ||||
-rw-r--r-- | CodeGen/CGExprScalar.cpp | 8 | ||||
-rw-r--r-- | include/clang/AST/Expr.h | 4 |
5 files changed, 7 insertions, 11 deletions
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<FloatingLiteral>(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<BuiltinType>(getType())->getKind() == BuiltinType::Float) return Value.convertToFloat(); else |