File 1203-matherr-must-not-fake-an-FP-exception.patch of Package erlang
From 0127f930e6aa2abc95ec4a95c9d5638d7e9bd512 Mon Sep 17 00:00:00 2001
From: Mikael Pettersson <mikpelinux@gmail.com>
Date: Sun, 17 Apr 2016 20:02:28 +0200
Subject: [PATCH] matherr() must not fake an FP exception
When FP exceptions are used, matherr() forces a fake FP exception,
which is interpreted as an error by the checking code after a math
routine call. This is wrong for several reasons:
- it's not necessary for error checking: when FP exceptions aren't
used, matherr() is a stub and no information is derived from it
being called
- it's not necessary for FPU maintenance: the FPU only needs to be
reprogrammed after an actual FP exception
- it causes false negatives: matherr() may be called even though
Erlang doesn't consider the case to be an error (exp() and pow()
underflows on Solaris for instance); with FP exceptions enabled
they are incorrectly considered errors
The fix is to remove all FP exception related code from matherr().
---
erts/emulator/sys/unix/sys_float.c | 5 -----
erts/emulator/sys/win32/sys_float.c | 3 +--
2 files changed, 1 insertion(+), 7 deletions(-)
diff --git a/erts/emulator/sys/unix/sys_float.c b/erts/emulator/sys/unix/sys_float.c
index 60661d9..9d2b25a 100644
--- a/erts/emulator/sys/unix/sys_float.c
+++ b/erts/emulator/sys/unix/sys_float.c
@@ -818,11 +818,6 @@ sys_chars_to_double(char* buf, double* fp)
int
matherr(struct exception *exc)
{
-#if !defined(NO_FPE_SIGNALS)
- volatile unsigned long *fpexnp = erts_get_current_fp_exception();
- if (fpexnp != NULL)
- *fpexnp = (unsigned long)__builtin_return_address(0);
-#endif
return 1;
}
diff --git a/erts/emulator/sys/win32/sys_float.c b/erts/emulator/sys/win32/sys_float.c
index a2b9bd1..2b2d6ab 100644
--- a/erts/emulator/sys/win32/sys_float.c
+++ b/erts/emulator/sys/win32/sys_float.c
@@ -139,8 +139,7 @@ sys_double_to_chars_ext(double fp, char *buffer, size_t buffer_size, size_t deci
int
matherr(struct _exception *exc)
{
- erl_fp_exception = 1;
- DEBUGF(("FP exception (matherr) (0x%x) (%d)\n", exc->type, erl_fp_exception));
+ DEBUGF(("FP exception (matherr) (0x%x)\n", exc->type));
return 1;
}
--
2.1.4