lfortran icon indicating copy to clipboard operation
lfortran copied to clipboard

parameter_13 test fails in LFortran Release mode with `-ffast-math`

Open certik opened this issue 1 year ago • 1 comments

I compiled LFortran with the following script:

#!/usr/bin/env bash

set -e
set -x

cmake \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_CXX_FLAGS_RELEASE="-Wall -Wextra -O3 -march=native -ffast-math -funroll-loops -DNDEBUG" \
    -DWITH_LLVM=yes \
    -DLFORTRAN_BUILD_ALL=yes \
    -DWITH_STACKTRACE=no \
    -DWITH_RUNTIME_STACKTRACE=yes \
    -DCMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH_LFORTRAN;$CONDA_PREFIX" \
    -DCMAKE_INSTALL_PREFIX=`pwd`/inst \
    -DCMAKE_INSTALL_LIBDIR=share/lfortran/lib \
    .
cmake --build . -j10 --target install

All tests pass except:

$ lfortran parameter_13.f90
1.99999999961700015e+00
ERROR STOP
$ echo $?
1

certik avatar Aug 12 '24 00:08 certik

This change fixes it:

--- a/integration_tests/parameter_13.f90
+++ b/integration_tests/parameter_13.f90
@@ -13,5 +13,5 @@ logical, parameter :: l = S < 2
 real(kind=merge(sp, dp, l)) :: y
 if (kind(y) /= sp) error stop
 print *, S
-if (abs(S - 1.9999999996170159_dp) > 1e-15_dp) error stop
+if (abs(S - 1.9999999996170159_dp) > 1e-13_dp) error stop
 end program

I think this is due to the -ffast-math flag that I supplied in the compilation of LFortran.

So probably we should not compile with -ffast-math.

certik avatar Aug 12 '24 00:08 certik