Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28602 Discussions

Compiler bug: backspace after non-advancing read

Lionel_Guez
Beginner
172 Views

Hello. Here is a test program:

 

 

$ cat test_backspace.f90
program test_backspace
  implicit none
  integer a(4)
  integer iostat
  character c
  open(unit=1, file="test_backspace.csv", status='old', action='read', &
       position='rewind')
  do
     read(unit=1, fmt='(a)', advance='no', iostat=iostat) c
     if (iostat /= 0) exit
  end do
  backspace(unit=1)
  read(unit=1, fmt=*) a
  close(unit=1)
  print *, "a = ", a
end program test_backspace

 

 

And here is a test input file:

 

 

$ cat test_backspace.csv
3 6
-2 0

 

 

Execution fails with a recent version of the Intel compiler:

 

 

$ ifx --version
ifx (IFX) 2023.1.0 20230320

$ ifx test_backspace.f90

$ a.out
forrtl: severe (24): end-of-file during read, unit 1, file /gpfsssd/scratch/rech/lmd/rdzt899/test_backspace.csv

 

 

Please note that it works with an older version of the Intel compiler:

 

 

$ ifort --version
ifort (IFORT) 19.1.3.304
20200925

$ ifort test_backspace.f90

$ a.out
 a =            3           6          -2           0

 

 

and it works with the GNU compiler:

 

 

$ gfortran --version
GNU Fortran (GCC) 11.3.1 20221121 (Red Hat 11.3.1-4)
Copyright (C) 2021 Free Software Foundation, Inc.

$ gfortran test_backspace.f90

$ a.out
 a =            3           6          -2           0

 

 

I think this is a bug in the recent version of the Intel compiler. The last execution of the non-advancing read statement creates an end-of-record condition. The backspace should bring the position back to the beginning of the record. It does not (this can also be seen with a debugger).

 

Would you fix this bug?

0 Kudos
1 Solution
Devorah_H_Intel
Moderator
149 Views

 

$ ifx test_backspace.f90 
$ ./a.out
 a =            3           6          -2           0
$ ifx --version
ifx (IFX) 2024.2.0 20240602
Copyright (C) 1985-2024 Intel Corporation. All rights reserved.

 

Please upgrade to the latest 2024.2 ifx

 

View solution in original post

0 Kudos
2 Replies
Steve_Lionel
Honored Contributor III
151 Views

Already fixed.

 

 

D:\Projects>ifx t.f90
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2024.2.0 Build 20240602
Copyright (C) 1985 - 2024 Intel Corporation. All rights reserved.

Microsoft (R) Incremental Linker Version 14.40.33811.0
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:t.exe
-subsystem:console
t.obj

D:\Projects>t.exe
 a =            3           6          -2           0

 

 

0 Kudos
Devorah_H_Intel
Moderator
150 Views

 

$ ifx test_backspace.f90 
$ ./a.out
 a =            3           6          -2           0
$ ifx --version
ifx (IFX) 2024.2.0 20240602
Copyright (C) 1985-2024 Intel Corporation. All rights reserved.

 

Please upgrade to the latest 2024.2 ifx

 

0 Kudos
Reply