Predefine __NO_MATH_ERRNO__ for -fno-math-errno.
authorJoseph Myers <joseph@codesourcery.com>
Wed, 12 Nov 2014 13:33:45 +0000 (13:33 +0000)
committerJoseph Myers <jsm28@gcc.gnu.org>
Wed, 12 Nov 2014 13:33:45 +0000 (13:33 +0000)
This patch adds a predefined macro __NO_MATH_ERRNO__ for when
-fno-math-errno is passed or implied.  This allows math.h to provide a
more accurate definition of the C99 math_errhandling macro that takes
this option into account, and allows for choice of libm functions to
be optimized at compile time based on this option.

(There may be a case for such interfaces for -fno-rounding-math
(default) and -fno-trapping-math as well, but as C99 standard pragmas
would allow those to vary on a per-block basis, predefined macros
would be problematic as the interface; you can't select a
-fno-trapping-math or -fno-rounding-math version of a function in a
standard header if a conforming program could then use "#pragma STDC
FENV_ACCESS ON" to require a -ftrapping-math -frounding-math version
in a particular block.  So built-in functions might be a better way of
providing access to information about those options.)

Bootstrapped with no regressions on x86_64-unknown-linux-gnu.  OK to
commit?

* cppbuiltin.c (define_builtin_macros_for_compilation_flags):
Define __NO_MATH_ERRNO__ if -fno-math-errno.
* doc/cpp.texi (__NO_MATH_ERRNO__): Document predefined macro.

c-family:
* c-cppbuiltin.c (c_cpp_builtins_optimize_pragma): Define and
undefine __NO_MATH_ERRNO__ based on changes to -fmath-errno state.

testsuite:
* gcc.dg/no-math-errno-1.c, gcc.dg/no-math-errno-2.c,
gcc.dg/no-math-errno-3.c, gcc.dg/no-math-errno-4.c: New tests.

From-SVN: r217420

gcc/ChangeLog
gcc/c-family/ChangeLog
gcc/c-family/c-cppbuiltin.c
gcc/cppbuiltin.c
gcc/doc/cpp.texi
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/no-math-errno-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/no-math-errno-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/no-math-errno-3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/no-math-errno-4.c [new file with mode: 0644]

index 9b422f484548a409878499d60e5c218933bd81cc..8d52622b1bf76d73e35accc037ce782b1c5512fd 100644 (file)
@@ -1,3 +1,9 @@
+2014-11-12  Joseph Myers  <joseph@codesourcery.com>
+
+       * cppbuiltin.c (define_builtin_macros_for_compilation_flags):
+       Define __NO_MATH_ERRNO__ if -fno-math-errno.
+       * doc/cpp.texi (__NO_MATH_ERRNO__): Document predefined macro.
+
 2014-11-12  Richard Biener  <rguenther@suse.de>
 
        * genmatch.c (::gen_transform): Add capture_info and
index 7feda0f185d2ac9d9c970caad384d087f9a26490..4eb90fc1b117011931170d3518c97175c3ca75e3 100644 (file)
@@ -1,3 +1,8 @@
+2014-11-12  Joseph Myers  <joseph@codesourcery.com>
+
+       * c-cppbuiltin.c (c_cpp_builtins_optimize_pragma): Define and
+       undefine __NO_MATH_ERRNO__ based on changes to -fmath-errno state.
+
 2014-11-12  Jakub Jelinek  <jakub@redhat.com>
 
        PR c/59708
index a4ed5c62ba7243eaa9c50927ff261a2762087058..c571d1b2e1ea569f456d24faf416490824c1af40 100644 (file)
@@ -549,6 +549,11 @@ c_cpp_builtins_optimize_pragma (cpp_reader *pfile, tree prev_tree,
   else if (prev->x_flag_signaling_nans && !cur->x_flag_signaling_nans)
     cpp_undef (pfile, "__SUPPORT_SNAN__");
 
+  if (!prev->x_flag_errno_math && cur->x_flag_errno_math)
+    cpp_undef (pfile, "__NO_MATH_ERRNO__");
+  else if (prev->x_flag_errno_math && !cur->x_flag_errno_math)
+    cpp_define (pfile, "__NO_MATH_ERRNO__");
+
   if (!prev->x_flag_finite_math_only && cur->x_flag_finite_math_only)
     {
       cpp_undef (pfile, "__FINITE_MATH_ONLY__");
index 3fc2f8adb83496cf25bc5bed8fc7b2e7add324a9..474f72407274ea55b75c9dfadd9668ada8adcc27 100644 (file)
@@ -102,6 +102,8 @@ define_builtin_macros_for_compilation_flags (cpp_reader *pfile)
     cpp_define (pfile, "__FAST_MATH__");
   if (flag_signaling_nans)
     cpp_define (pfile, "__SUPPORT_SNAN__");
+  if (!flag_errno_math)
+    cpp_define (pfile, "__NO_MATH_ERRNO__");
 
   cpp_define_formatted (pfile, "__FINITE_MATH_ONLY__=%d",
                        flag_finite_math_only);
index f32aac70b6e86871727da81f4cb2cb355353cae6..df04d0baf467485fc9f993690da4e290321a145a 100644 (file)
@@ -2421,6 +2421,10 @@ Annex G requirements (for example, because @option{-fcx-limited-range}
 was used).  If 1 or more, it indicates that it is intended to support
 those requirements; this does not mean that all relevant language
 features are supported by GCC.
+
+@item __NO_MATH_ERRNO__
+This macro is defined if @option{-fno-math-errno} is used, or enabled
+by another option such as @option{-ffast-math} or by default.
 @end table
 
 @node System-specific Predefined Macros
index c72e75f781c223bc2a8c099653a2277aa0cd3969..0b5b0946982207794a5986432e319092f4b09de7 100644 (file)
@@ -1,3 +1,8 @@
+2014-11-12  Joseph Myers  <joseph@codesourcery.com>
+
+       * gcc.dg/no-math-errno-1.c, gcc.dg/no-math-errno-2.c,
+       gcc.dg/no-math-errno-3.c, gcc.dg/no-math-errno-4.c: New tests.
+
 2014-11-12  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR testsuite/63830
diff --git a/gcc/testsuite/gcc.dg/no-math-errno-1.c b/gcc/testsuite/gcc.dg/no-math-errno-1.c
new file mode 100644 (file)
index 0000000..2659f59
--- /dev/null
@@ -0,0 +1,7 @@
+/* Test __NO_MATH_ERRNO__ is defined with -fno-math-errno.  */
+/* { dg-do compile } */
+/* { dg-options "-fno-math-errno" } */
+
+#ifndef __NO_MATH_ERRNO__
+#error "__NO_MATH_ERRNO__ not defined"
+#endif
diff --git a/gcc/testsuite/gcc.dg/no-math-errno-2.c b/gcc/testsuite/gcc.dg/no-math-errno-2.c
new file mode 100644 (file)
index 0000000..f44a997
--- /dev/null
@@ -0,0 +1,7 @@
+/* Test __NO_MATH_ERRNO__ is defined with -ffast-math.  */
+/* { dg-do compile } */
+/* { dg-options "-ffast-math" } */
+
+#ifndef __NO_MATH_ERRNO__
+#error "__NO_MATH_ERRNO__ not defined"
+#endif
diff --git a/gcc/testsuite/gcc.dg/no-math-errno-3.c b/gcc/testsuite/gcc.dg/no-math-errno-3.c
new file mode 100644 (file)
index 0000000..e19e94f
--- /dev/null
@@ -0,0 +1,7 @@
+/* Test __NO_MATH_ERRNO__ is not defined with -fmath-errno.  */
+/* { dg-do compile } */
+/* { dg-options "-fmath-errno" } */
+
+#ifdef __NO_MATH_ERRNO__
+#error "__NO_MATH_ERRNO__ defined"
+#endif
diff --git a/gcc/testsuite/gcc.dg/no-math-errno-4.c b/gcc/testsuite/gcc.dg/no-math-errno-4.c
new file mode 100644 (file)
index 0000000..c6daa12
--- /dev/null
@@ -0,0 +1,17 @@
+/* Test __NO_MATH_ERRNO__ is defined and undefined by pragmas.  */
+/* { dg-do compile } */
+/* { dg-options "-fmath-errno" } */
+
+#ifdef __NO_MATH_ERRNO__
+#error "__NO_MATH_ERRNO__ defined"
+#endif
+
+#pragma GCC optimize "-fno-math-errno"
+#ifndef __NO_MATH_ERRNO__
+#error "__NO_MATH_ERRNO__ not defined"
+#endif
+
+#pragma GCC optimize "-fmath-errno"
+#ifdef __NO_MATH_ERRNO__
+#error "__NO_MATH_ERRNO__ defined"
+#endif