summaryrefslogtreecommitdiff
path: root/acinclude.m4
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2020-06-09 09:41:51 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2020-06-09 09:41:51 +0000
commit536f0395a0859e20a44d0aa796034f4aa2481f1f (patch)
treea5733b345e18845acffb4958b12854aa5a6d998d /acinclude.m4
parent49b578c61265818a86648908900046cd65188ff6 (diff)
downloadmpfr-536f0395a0859e20a44d0aa796034f4aa2481f1f.tar.gz
[acinclude.m4] Fixed MPFR_CHECK_MP_LIMB_T_VS_LONG macro by forcing
MPFR_USE_STATIC_ASSERT to 1 before including mpfr-sassert.h, i.e. by requiring static assertions: because AC_COMPILE_IFELSE is used (i.e. just compiling, no linking), the test could incorrectly succeed when MPFR_USE_STATIC_ASSERT was not defined, i.e. whatever the value of "(mp_limb_t) -1 >= (unsigned long) -1"; indeed, in this case, MPFR_ASSERTN() was used instead of a static assertion, and since the macro was not defined here, MPFR_ASSERTN was regarded as a function (without a prototype), which was fine for compiling (except when the compiler is configured to regard warnings such as missing prototype as errors). In short, one could get "yes" while long was larger than mp_limb_t. Note: In uncommon cases (non-standard compiler...), one can still get "no" while a long fits in mp_limb_t, but this isn't much an issue as the MPFR code should work in such a case. Moreover, src/mpfr-impl.h will also have the chance to set MPFR_LONG_WITHIN_LIMB in practice. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@13948 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'acinclude.m4')
-rw-r--r--acinclude.m429
1 files changed, 10 insertions, 19 deletions
diff --git a/acinclude.m4 b/acinclude.m4
index 8f34fbc59..aab0f49ee 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -995,27 +995,15 @@ esac
dnl MPFR_CHECK_MP_LIMB_T_VS_LONG
dnl ----------------------------
-dnl Check that a long can fit in a mp_limb_t.
-dnl If so, it set the define MPFR_LONG_WITHIN_LIMB
-dnl FIXME: The following code is wrong when using:
-dnl -std=c99 -pedantic-errors -Wno-error=overlength-strings
-dnl because static assertions are not supported, so that MPFR_ASSERTN
-dnl is used, but it is not defined by "mpfr-sassert.h". The consequence
-dnl is that the program fails, and MPFR_LONG_WITHIN_LIMB is not defined
-dnl while it should be. Conversely, using MPFR_ASSERTN would be incorrect
-dnl as we use AC_COMPILE_IFELSE here, thus it must be an assertion checked
-dnl at compile time. Before fixing this bug, find a way to test with
-dnl MPFR_LONG_WITHIN_LIMB undefined; this is necessary for code coverage
-dnl and possibly to find new bugs, like in r12252:
-dnl ./configure --enable-assert=full \
-dnl 'CFLAGS=-std=c99 -O3 -pedantic-errors -Wno-error=overlength-strings'
+dnl Check whether a long fits in mp_limb_t.
+dnl Note: Since AC_COMPILE_IFELSE is used, the test needs a static assertion.
+dnl If static assertions are not supported, one gets "no" even though a long
+dnl fits in mp_limb_t. Therefore, code without MPFR_LONG_WITHIN_LIMB defined
+dnl needs to be portable.
dnl According to the GMP developers, a limb is always as large as a long,
-dnl except when __GMP_SHORT_LIMB is defined, but this is never defined:
+dnl except when __GMP_SHORT_LIMB is defined. It is currently never defined:
dnl https://gmplib.org/list-archives/gmp-discuss/2018-February/006190.html
-dnl FIXME: This is not safe. The fact that __GMP_SHORT_LIMB cannot occur
-dnl is not documented, and gmp.h has such a code probably because it may
-dnl occur in the future (or the user may want to override the default
-dnl choice).
+dnl but it is not clear whether this could change in the future.
AC_DEFUN([MPFR_CHECK_MP_LIMB_T_VS_LONG], [
AC_REQUIRE([MPFR_CONFIGS])
AC_CACHE_CHECK([for long to fit in mp_limb_t], mpfr_cv_long_within_limb, [
@@ -1023,6 +1011,9 @@ saved_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS -I$srcdir/src"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <gmp.h>
+/* Make sure that a static assertion is used (not MPFR_ASSERTN). */
+#undef MPFR_USE_STATIC_ASSERT
+#define MPFR_USE_STATIC_ASSERT 1
#include "mpfr-sassert.h"
]], [[
MPFR_STAT_STATIC_ASSERT ((mp_limb_t) -1 >= (unsigned long) -1);