Gfortran "ffpe-trap" compiling options

I want to use gfortran compiling options -g -fbacktrace -ffpe-trap=zero,overflow,underflow,invalid,denormal -Wall -fcheck=all to compile the test code which has invalid IEEE_XXXX_FLAG.

compiler: WSL ubuntu 20.04 gfortran 9.3

The code like this

program main
    implicit none
    real::a,b,c
    a=0.0
    b=0.0
    c=a/b
    write(*,*)c
    pause
end program main

If I don’t use these options, the output shows below (pause is important)

$ gfortran test.f90 && ./a.out
test.f90:8:9:

    8 |     pause
      |         1
Warning: Deleted feature: PAUSE statement at (1)
              NaN
PAUSE
To resume execution, type go.  Other input will terminate the job.

Note: The following floating-point exceptions are signalling: IEEE_INVALID_FLAG

If I use these options

$ gfortran -g -fbacktrace -ffpe-trap=zero,overflow,underflow,invalid,denormal -Wall -fcheck=all test.f90 && ./a.out
test.f90:8:9:

    8 |     pause
      |         1
Warning: Deleted feature: PAUSE statement at (1)

just show this.

However ,When I use these compiling options on godbolt,
Its output

The more important information .f90:6 shows.

So Can personal computer show the same error info?

Thanks

1 Like

To silence the warning about pause, you can use the -std=legacy option. On Windows 10, using GNU Fortran (GCC) 12.0.0 20210718 from equation.com and compiling your code with

gfortran -std=legacy -g -fbacktrace -ffpe-trap=zero,overflow,underflow,invalid,denormal -Wall fcheck=all trap.f90

gives when running

Program received signal SIGFPE: Floating-point exception - erroneous arithmetic operation.


Backtrace for this error:
#0  0x42f94b
#1  0x425814
#2  0x40ca31
#3  0xfb2ad57
#4  0x106c826e
#5  0x106559c9
#6  0x106c727d
#7  0x40159f
#8  0x401668
#9  0x4013c0
#10  0x4014f5
#11  0xe7254df
#12  0x1062485a
#13  0xffffffff

On WSL 2, using GNU Fortran (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0 with the same options as above gives at run time

Program received signal SIGFPE: Floating-point exception - erroneous arithmetic operation.

Backtrace for this error:
#0  0x7f60ece9b700 in ???
#1  0x7f60ece9a8a5 in ???
#2  0x7f60eccce20f in ???
#3  0x555c224d41fa in MAIN__
	at /mnt/c/fortran/test/trap.f90:6
#4  0x555c224d42c3 in main
	at /mnt/c/fortran/test/trap.f90:9
Floating point exception

I wonder why we are getting different results for WSL. Are you using WSL 1 or 2? You can check by running wsl -l -v from Windows CMD.

I am using WSL 1 ,So may it is the key :thinking:,Thanks a lot :grinning:

update : using gcc version 11.2.0 (GCC) from equation.com gives this error

and if using gdb debug the binarygdb a.exe,it shows

> r
.......
Thread 1 received signal SIGFPE, Arithmetic exception.
0x00007ff7812e15a0 in MAIN__ () at 1.f90:6
6           c=a/b

and gives line 6. By the way ,WSL1 shows nothing as before.