Hi,

On Wed, Mar 11, 2026 at 03:07:10PM +0100, Peter Eisentraut wrote:
> On 11.03.26 14:43, Andres Freund wrote:
> > Hi,
> > 
> > On 2026-03-11 11:52:28 +0000, Bertrand Drouvot wrote:
> > > while working on a patch (not shared yet), I had issues with 
> > > floating-point and
> > > realized that we don't defend against -ffast-math in meson builds. We 
> > > defend
> > > against in autoconf (because we don't want fast-math optimizations [1]), 
> > > so the
> > > attached does the same for meson.
> > 
> > I don't find this (nor the autoconf check) particularly likely to be
> > helpful. The most likely way the flag would unintentionally be added would 
> > be
> > via the cflags of some dependency - which won't be picked up by the tests.
> > 
> > However we do have tests during the builds that should pick it up, in date.c
> > and timestamp.c...
> 
> The existing check in configure is because certain Linux distributions used
> to compile everything with -ffast-math to be "faster", and that kept
> breaking PostgreSQL and so we wanted to stop them very early. These are
> gone, and the defenses in the code like date.c should be sufficient for any
> new attempts.  I think we could remove the check in configure.

Oh, I did not see that we also have __FAST_MATH__ check in some C files. The 
reason
is that I build with:

CFLAGS="-ffast-math" CC="gcc" meson setup meson_build and -Dc_args="-Og -ggdb"
and that did not produce the error at compilation time.

But I got some regression tests failing like:

--- /home/postgres/postgresql/postgres/src/test/regress/expected/numeric.out
+++ 
/home/postgres/postgresql/postgres/meson_build/testrun/regress/regress/results/numeric.out
@@ -1630,22 +1630,7 @@
     (0, 0, 1, 2147483647),
     (1, 1, 0, 2147483647)
   ) as sample(oper, low, high, cnt);
-    oper     |     low     |    high     |    cnt     | width_bucket
--------------+-------------+-------------+------------+--------------
-        10.5 | -1.797e+308 |  1.797e+308 |          1 |            1
-        10.5 | -1.797e+308 |  1.797e+308 |          2 |            2
-        10.5 | -1.797e+308 |  1.797e+308 |          3 |            2
- 4.4925e+307 | -8.985e+307 |  8.985e+307 |         10 |            8
-        10.5 |  1.797e+308 | -1.797e+308 |          1 |            1
-        10.5 |  1.797e+308 | -1.797e+308 |          2 |            2
-        10.5 |  1.797e+308 | -1.797e+308 |          3 |            2
- 4.4925e+307 |  8.985e+307 | -8.985e+307 |         10 |            3
-           0 |           0 |      5e-324 |          4 |            1
-      5e-324 |           0 |      5e-324 |          4 |            5
-           0 |           0 |           1 | 2147483647 |            1
-           1 |           1 |           0 | 2147483647 |            1
-(12 rows)
-
+ERROR:  "0.00000000..<LOT OF 0>..000005" is out of range for type double 
precision

or

--- /home/postgres/postgresql/postgres/src/test/regress/expected/money.out
+++ 
/home/postgres/postgresql/postgres/meson_build/testrun/regress/regress/results/money.out
 
@@ -536,7 +536,7 @@
 SELECT '92233720368547758.07'::money * 2::float8;
 ERROR:  money out of range
 SELECT '-1'::money / 1.175494e-38::float4;
-ERROR:  money out of range
+ERROR:  "0.00000000000000000000000000000000000001175494" is out of range for 
type real

But if I use:

CC="gcc" meson setup meson_build and -Dc_args="-Og -ggdb -ffast-math" then the
error happens at compilation time.

The check added in the patch would also catch the CFLAGS="-ffast-math" case.

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com


Reply via email to