malloc etc. tests: use volatile more consistently
[gnulib.git] / m4 / rintl.m4
blob853836fb0216ad4a6d8f1b0c562a72779dff42de
1 # rintl.m4
2 # serial 11
3 dnl Copyright (C) 2011-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7 dnl This file is offered as-is, without any warranty.
9 AC_DEFUN([gl_FUNC_RINTL],
11   AC_REQUIRE([gl_MATH_H_DEFAULTS])
12   AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
14   dnl Persuade glibc <math.h> to declare rintl().
15   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
17   dnl Determine RINTL_LIBM.
18   gl_MATHFUNC([rintl], [long double], [(long double)])
19   if test $gl_cv_func_rintl_no_libm = yes \
20      || test $gl_cv_func_rintl_in_libm = yes; then
21     if test $REPLACE_RINTL = 0; then
22       AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
23       AC_CACHE_CHECK([whether rintl works],
24         [gl_cv_func_rintl_works],
25         [
26           saved_LIBS="$LIBS"
27           LIBS="$LIBS $RINTL_LIBM"
28           AC_RUN_IFELSE(
29             [AC_LANG_SOURCE([[
30 #include <math.h>
31 #undef rintl
32 extern
33 #ifdef __cplusplus
34 "C"
35 #endif
36 long double rintl (long double);
37 static long double dummy (long double x) { return 0; }
38 int main (int argc, char *argv[])
40   long double (* volatile my_rintl) (long double) = argc ? rintl : dummy;
41   int result = 0;
42   /* This test fails on NetBSD 9.0.  */
43   {
44     volatile long double x = -0.3L;
45     long double y = my_rintl (x);
46     if (!(y == 0.0L))
47       result |= 1;
48   }
49   return result;
51             ]])],
52             [gl_cv_func_rintl_works=yes],
53             [gl_cv_func_rintl_works=no],
54             [case "$host_os" in
55                                    # Guess yes on glibc systems.
56                *-gnu* | gnu*)      gl_cv_func_rintl_works="guessing yes" ;;
57                                    # Guess yes on musl systems.
58                *-musl* | midipix*) gl_cv_func_rintl_works="guessing yes" ;;
59                                    # Guess yes on native Windows.
60                mingw* | windows*)  gl_cv_func_rintl_works="guessing yes" ;;
61                                    # If we don't know, obey --enable-cross-guesses.
62                *)                  gl_cv_func_rintl_works="$gl_cross_guess_normal" ;;
63              esac
64             ])
65           LIBS="$saved_LIBS"
66         ])
67       case "$gl_cv_func_rintl_works" in
68         *yes) ;;
69         *) REPLACE_RINTL=1 ;;
70       esac
71     fi
72   else
73     HAVE_RINTL=0
74   fi
75   if test $HAVE_RINTL = 0 || test $REPLACE_RINTL = 1; then
76     dnl Find libraries needed to link lib/rintl.c.
77     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
78       AC_REQUIRE([gl_FUNC_RINT])
79       RINTL_LIBM="$RINT_LIBM"
80     else
81       RINTL_LIBM=
82     fi
83   fi
84   AC_SUBST([RINTL_LIBM])