diff mbox

PR79017 workaround incomplete C99 math on darwin

Message ID 20170109171603.GJ13348@redhat.com
State New
Headers show

Commit Message

Jonathan Wakely Jan. 9, 2017, 5:16 p.m. UTC
Older versions of OS X (at least Leopard) are missing some
declarations of C99 functions from <math.h>, which causes our
configure test to decide that all C99 functions are missing from
<math.h>. Rather then splitting up the check into dozens of smaller
checks for individual functions (which would be stage 1 material) this
just adds a special case for the six missing functions, so that darwin
checks for them separately and defaines a new macro to say they're
missing.

	PR libstdc++/79017
	* acinclude.m4 (GLIBCXX_CHECK_C99_TR1): Check for llrint and llround
	functions separately on darwin and if they're missing define
	_GLIBCXX_NO_C99_ROUNDING_FUNCS.
	* config.h.in: Regenerate.
	* configure: Regenerate.
	* include/c_global/cmath [_GLIBCXX_NO_C99_ROUNDING_FUNCS] (llrint)
	(llrintf, llrintl, llround, llroundf, llroundl): Do not define.

Tested x86_64-linux, committed to trunk.
commit 2802004b233a381e67afee0d9fc4b83712bc7b56
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Jan 9 15:22:03 2017 +0000

    PR79017 workaround incomplete C99 math on darwin
    
    	PR libstdc++/79017
    	* acinclude.m4 (GLIBCXX_CHECK_C99_TR1): Check for llrint and llround
    	functions separately on darwin and if they're missing define
    	_GLIBCXX_NO_C99_ROUNDING_FUNCS.
    	* config.h.in: Regenerate.
    	* configure: Regenerate.
    	* include/c_global/cmath [_GLIBCXX_NO_C99_ROUNDING_FUNCS] (llrint)
    	(llrintf, llrintl, llround, llroundf, llroundl): Do not define.

Comments

Mike Stump Jan. 9, 2017, 6:43 p.m. UTC | #1
On Jan 9, 2017, at 9:16 AM, Jonathan Wakely <jwakely@redhat.com> wrote:
> 
> Older versions of OS X (at least Leopard) are missing some
> declarations of C99 functions from <math.h>, which causes our
> configure test to decide that all C99 functions are missing from
> <math.h>. Rather then splitting up the check into dozens of smaller
> checks for individual functions (which would be stage 1 material) this
> just adds a special case for the six missing functions, so that darwin
> checks for them separately and defaines a new macro to say they're
> missing.
> 
> 	PR libstdc++/79017
> 	* acinclude.m4 (GLIBCXX_CHECK_C99_TR1): Check for llrint and llround
> 	functions separately on darwin and if they're missing define
> 	_GLIBCXX_NO_C99_ROUNDING_FUNCS.
> 	* config.h.in: Regenerate.
> 	* configure: Regenerate.
> 	* include/c_global/cmath [_GLIBCXX_NO_C99_ROUNDING_FUNCS] (llrint)
> 	(llrintf, llrintl, llround, llroundf, llroundl): Do not define.

Another possibility might be possible if llrint is the same as lrint and lrint is present... then liberty can define forwarders on a per function basis if they aren't there.

I think this is the case when sizeof (long long) == sizeof(long).
diff mbox

Patch

diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
index eef107a..4e04cce 100644
--- a/libstdc++-v3/acinclude.m4
+++ b/libstdc++-v3/acinclude.m4
@@ -1890,12 +1890,14 @@  AC_DEFUN([GLIBCXX_CHECK_C99_TR1], [
 		  lgamma(0.0);
 		  lgammaf(0.0f);
 		  lgammal(0.0l);
+		  #ifndef __APPLE__ /* see below */
 		  llrint(0.0);
 		  llrintf(0.0f);
 		  llrintl(0.0l);
 		  llround(0.0);
 		  llroundf(0.0f);
 		  llroundl(0.0l);
+		  #endif
 		  log1p(0.0);
 		  log1pf(0.0f);
 		  log1pl(0.0l);
@@ -1954,6 +1956,29 @@  AC_DEFUN([GLIBCXX_CHECK_C99_TR1], [
     AC_DEFINE(_GLIBCXX_USE_C99_MATH_TR1, 1,
 	      [Define if C99 functions or macros in <math.h> should be imported
 	      in <tr1/cmath> in namespace std::tr1.])
+
+    case "${target_os}" in
+      darwin*)
+        AC_MSG_CHECKING([for ISO C99 rounding functions in <math.h>])
+        AC_CACHE_VAL(glibcxx_cv_c99_math_llround, [
+          AC_TRY_COMPILE([#include <math.h>],
+		 [llrint(0.0);
+		  llrintf(0.0f);
+		  llrintl(0.0l);
+		  llround(0.0);
+		  llroundf(0.0f);
+		  llroundl(0.0l);
+		 ],
+		 [glibcxx_cv_c99_math_llround=yes],
+		 [glibcxx_cv_c99_math_llround=no])
+          ])
+	AC_MSG_RESULT($glibcxx_cv_c99_math_llround)
+        ;;
+    esac
+    if test x"$glibcxx_cv_c99_math_llround" = x"no"; then
+      AC_DEFINE(_GLIBCXX_NO_C99_ROUNDING_FUNCS, 1,
+		[Define if C99 llrint and llround functions are missing from <math.h>.])
+    fi
   fi
 
   # Check for the existence of <inttypes.h> functions (NB: doesn't make
diff --git a/libstdc++-v3/include/c_global/cmath b/libstdc++-v3/include/c_global/cmath
index 3630a5b..6e7508f 100644
--- a/libstdc++-v3/include/c_global/cmath
+++ b/libstdc++-v3/include/c_global/cmath
@@ -1012,12 +1012,14 @@  _GLIBCXX_END_NAMESPACE_VERSION
 #undef lgamma
 #undef lgammaf
 #undef lgammal
+#ifndef _GLIBCXX_NO_C99_ROUNDING_FUNCS
 #undef llrint
 #undef llrintf
 #undef llrintl
 #undef llround
 #undef llroundf
 #undef llroundl
+#endif
 #undef log1p
 #undef log1pf
 #undef log1pl
@@ -1143,6 +1145,7 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
   using ::lgammaf;
   using ::lgammal;
 
+#ifndef _GLIBCXX_NO_C99_ROUNDING_FUNCS
   using ::llrint;
   using ::llrintf;
   using ::llrintl;
@@ -1150,6 +1153,7 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
   using ::llround;
   using ::llroundf;
   using ::llroundl;
+#endif
 
   using ::log1p;
   using ::log1pf;