]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Move -ffast-math defense to float.c and remove the configure check.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 15 Mar 2026 23:34:52 +0000 (19:34 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 15 Mar 2026 23:34:52 +0000 (19:34 -0400)
We had defenses against -ffast-math in timestamp-related files,
which is a pretty obsolete place for them since we've not supported
floating-point timestamps in a long time.  Remove those and instead
put one in float.c, which is still broken by using this switch.
Add some commentary to put more color on why it's a bad idea.

Also remove the check from configure.  That was just there to fail
faster, but it doesn't really seem necessary anymore, and besides
we have no corresponding check in meson.build.

Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Suggested-by: Andres Freund <andres@anarazel.de>
Suggested-by: Peter Eisentraut <peter@eisentraut.org>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/abFXfKC8zR0Oclon%40ip-10-97-1-34.eu-west-3.compute.internal

configure
configure.ac
src/backend/utils/adt/date.c
src/backend/utils/adt/float.c
src/backend/utils/adt/timestamp.c
src/interfaces/ecpg/pgtypeslib/interval.c
src/interfaces/ecpg/pgtypeslib/timestamp.c

index 4c789bd9289b5c9affed8ab17ac5a6971627d183..f69331f07485f6ceca4276cbee0dd91fef2230d7 100755 (executable)
--- a/configure
+++ b/configure
@@ -7700,29 +7700,6 @@ fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
 
-# Defend against gcc -ffast-math
-if test "$GCC" = yes; then
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-int
-main ()
-{
-#ifdef __FAST_MATH__
-choke me
-#endif
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
-
-else
-  as_fn_error $? "do not put -ffast-math in CFLAGS" "$LINENO" 5
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-fi
-
 # Defend against clang being used on x86-32 without SSE2 enabled.  As current
 # versions of clang do not understand -fexcess-precision=standard, the use of
 # x87 floating point operations leads to problems like isinf possibly returning
index 9edffe481a60eb305b79115cfe132adaa4b8c451..fead9a6ce9956c70ca4fda6ea5e04b2449ade294 100644 (file)
@@ -786,13 +786,6 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM([], [return 0;])],
   [AC_MSG_RESULT(no)
    AC_MSG_ERROR([cannot proceed])])
 
-# Defend against gcc -ffast-math
-if test "$GCC" = yes; then
-AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [@%:@ifdef __FAST_MATH__
-choke me
-@%:@endif])], [], [AC_MSG_ERROR([do not put -ffast-math in CFLAGS])])
-fi
-
 # Defend against clang being used on x86-32 without SSE2 enabled.  As current
 # versions of clang do not understand -fexcess-precision=standard, the use of
 # x87 floating point operations leads to problems like isinf possibly returning
index 621b9175c1200b894851257b1f42bec3de4e1c61..87c063fa0cd0e5111181b69a7b92b4fcb0f3348f 100644 (file)
 #include "utils/skipsupport.h"
 #include "utils/sortsupport.h"
 
-/*
- * gcc's -ffast-math switch breaks routines that expect exact results from
- * expressions like timeval / SECS_PER_HOUR, where timeval is double.
- */
-#ifdef __FAST_MATH__
-#error -ffast-math is known to break this code
-#endif
-
 
 /* common code for timetypmodin and timetztypmodin */
 static int32
index 641e7de21a0dad61929510f4ad46d350cd51501e..f77f73820d77fa6283bd942703bec0261d64df32 100644 (file)
 #include "utils/sortsupport.h"
 
 
+/*
+ * Reject building with gcc's -ffast-math switch.  It breaks our handling of
+ * float Infinity and NaN values (via -ffinite-math-only), causes results to
+ * be less accurate than expected (via -funsafe-math-optimizations and
+ * -fexcess-precision=fast), and causes some math error reports to be missed
+ * (via -fno-math-errno).  Unfortunately we can't easily detect cases where
+ * those options were given individually, but this at least catches the most
+ * obvious case.
+ *
+ * We test this only here, not in any header file, to allow extensions to use
+ * -ffast-math if they need to.  But the inline functions in float.h will
+ * misbehave in such an extension, so its authors had better be careful.
+ */
+#ifdef __FAST_MATH__
+#error -ffast-math is known to break this code
+#endif
+
 /*
  * Configurable GUC parameter
  *
index 6f8cf29c9105c1c0f6bf62c3ec0498a2358c492c..50a73fd24ec88a55367dd97978d3b1a341466ff2 100644 (file)
 #include "utils/skipsupport.h"
 #include "utils/sortsupport.h"
 
-/*
- * gcc's -ffast-math switch breaks routines that expect exact results from
- * expressions like timeval / SECS_PER_HOUR, where timeval is double.
- */
-#ifdef __FAST_MATH__
-#error -ffast-math is known to break this code
-#endif
 
 /* Set at postmaster start */
 TimestampTz PgStartTime;
index e452a088f9e5400a8dcd728a0d56b022eecf4563..463455398f1c464e153a92f10c0ae8c0e1d97b55 100644 (file)
@@ -6,10 +6,6 @@
 #include <math.h>
 #include <limits.h>
 
-#ifdef __FAST_MATH__
-#error -ffast-math is known to break this code
-#endif
-
 #include "common/string.h"
 #include "dt.h"
 #include "pgtypes_error.h"
index 7cf433266f45855bf5b491e4fe970658579f51d6..9bf1b91455333adb0be63086e54df90536381fc5 100644 (file)
@@ -7,10 +7,6 @@
 #include <limits.h>
 #include <math.h>
 
-#ifdef __FAST_MATH__
-#error -ffast-math is known to break this code
-#endif
-
 #include "common/int.h"
 #include "dt.h"
 #include "pgtypes_date.h"