aboutsummaryrefslogtreecommitdiffstats
path: root/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
commite62a8a353c3b21b551c00b9025800d3352e5349e (patch)
treea37067a905622f829f744199fd5a0f2ba8cdb41e /lib/VMCore/Core.cpp
parentb8033e821d9ccad10ba8770c4561600a3e9ce6cc (diff)
downloadexternal_llvm-e62a8a353c3b21b551c00b9025800d3352e5349e.zip
external_llvm-e62a8a353c3b21b551c00b9025800d3352e5349e.tar.gz
external_llvm-e62a8a353c3b21b551c00b9025800d3352e5349e.tar.bz2
Fixing a bug creating floating point constants of type other
than double through the C bindings. Thanks to Tomas Lindquist Olsen for reporting it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@46656 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Core.cpp')
-rw-r--r--lib/VMCore/Core.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/lib/VMCore/Core.cpp b/lib/VMCore/Core.cpp
index 8722785..0c913ff 100644
--- a/lib/VMCore/Core.cpp
+++ b/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 ...................................--*/