summaryrefslogtreecommitdiff
path: root/tests/mpfr-test.h
diff options
context:
space:
mode:
Diffstat (limited to 'tests/mpfr-test.h')
-rw-r--r--tests/mpfr-test.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/mpfr-test.h b/tests/mpfr-test.h
index e33fc19ae..7e8986f3f 100644
--- a/tests/mpfr-test.h
+++ b/tests/mpfr-test.h
@@ -37,6 +37,52 @@ https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
#include "mpfr-impl.h"
+/* Avoid a GCC bug on Sparc, at least when using TLS. The MPFR library
+ * itself is not affected, only a particular test. Normal code using
+ * the MPFR library should not be affected either, as the bug occurs
+ * when accessing __gmpfr_flags directly (and the public mpfr.h header
+ * file does not provide any macro that accesses an internal variable
+ * directly). So a workaround for the tests is the best solution.
+ *
+ * This bug, which could be observed under Debian with GCC 4.5.3 and
+ * sparc-sun-solaris2.10 with GCC 5.5.0 when TLS and optimizations
+ * are used[*], makes test programs using bad_cases() crash (SIGSEGV)
+ * in this function at:
+ *
+ * if (mpfr_nanflag_p () || mpfr_overflow_p () || mpfr_underflow_p ())
+ *
+ * Debugging shows that any attempt to access __gmpfr_flags directly
+ * in the loop makes the program crash at this moment. This bug is not
+ * present in the assembly code generated by -S, but is visible after a
+ * normal compilation + link, when tracing the assembly code with gdb.
+ * The workaround is to disable the macros from mpfr-impl.h that access
+ * __gmpfr_flags directly. This bug may have been fixed in more recent
+ * GCC versions, but it is safe to enable this workaround in all GCC
+ * versions.
+ *
+ * [*] This is the default. Disabling TLS or recompiling the tests
+ * without optimizations (-O0) makes the crash disappear.
+ *
+ * Mentions of these crashes:
+ * https://sympa.inria.fr/sympa/arc/mpfr/2011-10/msg00045.html [Debian]
+ * https://sympa.inria.fr/sympa/arc/mpfr/2011-10/msg00055.html [Debian]
+ * https://sympa.inria.fr/sympa/arc/mpfr/2011-12/msg00000.html [Solaris 10]
+ * https://sympa.inria.fr/sympa/arc/mpfr/2011-12/msg00001.html [Solaris 10]
+ * https://sympa.inria.fr/sympa/arc/mpfr/2011-12/msg00002.html
+ * https://sympa.inria.fr/sympa/arc/mpfr/2016-03/msg00061.html [Solaris 10]
+ * https://sympa.inria.fr/sympa/arc/mpfr/2016-03/msg00063.html
+ * https://sympa.inria.fr/sympa/arc/mpfr/2020-06/msg00015.html [Solaris 10]
+ * https://sympa.inria.fr/sympa/arc/mpfr/2020-06/msg00020.html
+ */
+#if defined(__GNUC__) && defined (__sparc__)
+# undef mpfr_underflow_p
+# undef mpfr_overflow_p
+# undef mpfr_nanflag_p
+# undef mpfr_inexflag_p
+# undef mpfr_erangeflag_p
+# undef mpfr_divby0_p
+#endif
+
#ifdef MPFR_TESTS_ABORT
# undef exit
# define exit(C) ((C) != 1 ? (exit)(C) : \