summaryrefslogtreecommitdiffstats
path: root/llvm/lib/VMCore/Core.cpp
diff options
context:
space:
mode:
authorGordon Henriksen <gordonhenriksen@mac.com>2008-02-02 01:07:50 +0000
committerGordon Henriksen <gordonhenriksen@mac.com>2008-02-02 01:07:50 +0000
commit931e121ad1ced8c656553e906929163d3f81662f (patch)
treeeb07de6cad34f4be9c1b37d18f699c802e18ff1c /llvm/lib/VMCore/Core.cpp
parent4e7ff941f1f29efcd99e71073e4a22e1d921c00a (diff)
downloadbcm5719-llvm-931e121ad1ced8c656553e906929163d3f81662f.tar.gz
bcm5719-llvm-931e121ad1ced8c656553e906929163d3f81662f.zip
Fixing a bug creating floating point constants of type other
than double through the C bindings. Thanks to Tomas Lindquist Olsen for reporting it. llvm-svn: 46656
Diffstat (limited to 'llvm/lib/VMCore/Core.cpp')
-rw-r--r--llvm/lib/VMCore/Core.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/llvm/lib/VMCore/Core.cpp b/llvm/lib/VMCore/Core.cpp
index 8722785bd39..0c913ffbf73 100644
--- a/llvm/lib/VMCore/Core.cpp
+++ b/llvm/lib/VMCore/Core.cpp
@@ -284,8 +284,30 @@ LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), N, SignExtend != 0));
}
+static const fltSemantics &SemanticsForType(Type *Ty) {
+ assert(Ty->isFloatingPoint() && "Type is not floating point!");
+ if (Ty == Type::FloatTy)
+ return APFloat::IEEEsingle;
+ if (Ty == Type::DoubleTy)
+ return APFloat::IEEEdouble;
+ if (Ty == Type::X86_FP80Ty)
+ return APFloat::x87DoubleExtended;
+ if (Ty == Type::FP128Ty)
+ return APFloat::IEEEquad;
+ if (Ty == Type::PPC_FP128Ty)
+ return APFloat::PPCDoubleDouble;
+ return APFloat::Bogus;
+}
+
LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N) {
- return wrap(ConstantFP::get(unwrap(RealTy), APFloat(N)));
+ APFloat APN(N);
+ APN.convert(SemanticsForType(unwrap(RealTy)), APFloat::rmNearestTiesToEven);
+ return wrap(ConstantFP::get(unwrap(RealTy), APN));
+}
+
+LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text) {
+ return wrap(ConstantFP::get(unwrap(RealTy),
+ APFloat(SemanticsForType(unwrap(RealTy)), Text)));
}
/*--.. Operations on composite constants ...................................--*/
OpenPOWER on IntegriCloud