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 e5a1282..01c563b 100644
--- a/AST/Expr.cpp
+++ b/AST/Expr.cpp
@@ -741,7 +741,7 @@
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 09909d8..6f25e12 100644
--- a/AST/StmtDumper.cpp
+++ b/AST/StmtDumper.cpp
@@ -307,7 +307,7 @@
}
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 11dd2ef..f878ca8 100644
--- a/AST/StmtPrinter.cpp
+++ b/AST/StmtPrinter.cpp
@@ -408,7 +408,7 @@
}
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 319ca82..155cf3b 100644
--- a/CodeGen/CGExprScalar.cpp
+++ b/CodeGen/CGExprScalar.cpp
@@ -93,13 +93,7 @@
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 5422869..94c02aa 100644
--- a/include/clang/AST/Expr.h
+++ b/include/clang/AST/Expr.h
@@ -223,7 +223,9 @@
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