fortran-lang / stdlib

Fortran Standard Library
https://stdlib.fortran-lang.org
MIT License
1.07k stars 166 forks source link

Execution failed for objects test_loadtxt_qp.exe and test_savetxt_qp.exe #547

Open Beliavsky opened 3 years ago

Beliavsky commented 3 years ago

Running GNU Fortran (GCC) 12.0.0 20210718 from equation.com on Windows 10, and using fpm

git checkout stdlib-fpm
fpm build --profile release
fpm test

I get

<ERROR> Execution failed for object " test_loadtxt_qp.exe "
<ERROR> Execution failed for object " test_savetxt_qp.exe "
<ERROR>*cmd_run*:stopping due to failed executions
STOP 1

Running the executable manually I get

c:\fortran\public_domain\github\stdlib>c:\fortran\public_domain\github\stdlib\build\gfortran_2A42023B310FA28D\test\test_loadtxt_qp.exe

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0  0x43c85b
#1  0x432724
#2  0x418e71
#3  0xe193ad57
#4  0xe2f0826e
#5  0xe2e959c9
#6  0xe2f0727d
#7  0xffffffff

c:\fortran\public_domain\github\stdlib>c:\fortran\public_domain\github\stdlib\build\gfortran_2A42023B310FA28D\test\test_savetxt_qp.exe

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0  0x44e42b
#1  0x4442f4
#2  0x41a6f1
#3  0xe193ad57
#4  0xe2f0826e
#5  0xe2e959c9
#6  0xe2f0727d
#7  0xffffffff
zoziha commented 3 years ago

Firstly, I tried to run fpm test on my laptop (windows 10, msys2-gfortran 10.3), and there was no failure. And I tried the gcc12 provided by equation.com, and it did get errors. It seems to be a bug with the gcc12 provided by equation.com! When loadtxt reads a real(qp) array from a file, an error may be reported, because of an uncertain bug about reading real(qp) array from files in gcc12 provided by equation.com (It does not seem to be any bug of loadtxt and savetxt.):

  1. tmp_qp.dat
    
    1.00000000000000000000000000000000000         4.00000000000000000000000000000000000      
    2.00000000000000000000000000000000000         5.00000000000000000000000000000000000      
    3.00000000000000000000000000000000000         6.00000000000000000000000000000000000      
2. `demo1.f90`
```fortran
program demo
    real(16) :: q0, q(2)
    open(1, file="tmp_qp.dat")

    !> test for qp scalar
    read(1, *) q0
    print *, q0

    !> test for qp array
    rewind(1)
    read(1, *) q
    print *, q

    close(1) 
end program demo

Output ✔

   1.00000000000000000000000000000000000
   1.00000000000000000000000000000000000         4.00000000000000000000000000000000000
  1. demo2.f90 Comment out the code to read real(qp) scalar, just keep reading real(qp) array.

    program demo
    real(16) :: q0, q(2)
    open(1, file="tmp_qp.dat")
    
    ! !> test for qp scalar
    ! read(1, *) q0
    ! print *, q0
    
    ! !> test for qp array
    ! rewind(1)
    read(1, *) q
    print *, q
    
    close(1) 
    end program demo

    Output ❌

    
    Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:

0 0x237901eb

1 0x23785f74

2 0x2376cb61

3 0x8d347ff7

4 0x8ecb20ce

5 0x8ec61453

6 0x8ecb0bfd

7 0xe375ffff

4. More Weird 🙃
```fortran
program demo
    real(16) :: q0, q(2)
    open(1, file="tmp_qp.dat")

    ! !> test for qp scalar
    ! read(1, *) q0
    print *, q0         !! Difference🔰 here.

    ! !> test for qp array
    ! rewind(1)
    read(1, *) q
    print *, q

    close(1) 
end program demo

Output ✔

   1.68057005478764111801640313826496845E-4932
   1.00000000000000000000000000000000000         4.00000000000000000000000000000000000

Gcc12 is still an experimental version, I haven't tested the gcc9~11 provided by equation.com, and I don't know if they also has this problem.

Beliavsky commented 3 years ago

Thanks @zoziha . Could you report this on GCC bugzilla?

zoziha commented 3 years ago

Okay, I plan to combine this issue with #532 and try to feed back to gcc. I am registering a gcc feedback account ...

ghost commented 3 years ago

These particular tests test_loadtxt_qp.exe and test_savetxt_qp.exe pass, using https://gcc.gnu.org/pub/gcc/snapshots/12-20210905/ on Windows.