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

Incorrect executable code from ifx 2024.0

NCarlson
New Contributor I
451 Views

I've been testing the latest ifx against my database of intel compiler bug reproducers and there is a old one from 2018 that both ifort 2021.11.0 and ifx 2024.0 continue to fail. I'm not sure I reported it originally (I can't find evidence that I did), but here it is.

The example reads ascii text from a file using unformatted stream input. The data is read into a character array buffer. If that buffer is an allocated allocatable array the read works as expected. However if the buffer is an allocated pointer array the buffer is filled with random garbage.

Here's the test case.  It should exit silently, but instead exits with an error (STOP 6).

program main

  use,intrinsic :: iso_fortran_env, only: iostat_end
  integer :: lun, ios, pos1, pos2, n
  character, allocatable :: buffer1(:)
  character, pointer :: buffer2(:)
  character(*), parameter :: string = 'one fish, two fish, red fish, blue fish'
  character, allocatable :: array(:)
  
  open(newunit=lun,file='junk')
  write(lun,'(a)') string
  close(lun)
  
  array = transfer(string, 'a', len(string))
  n = size(array)
  
  !! Read into allocatable character buffer -- THIS WORKS
  open(newunit=lun,file='junk',action='read',access='stream',iostat=ios)
  inquire(lun,pos=pos1)
  allocate(buffer1(100))
  read(lun,iostat=ios) buffer1
  if (ios /= iostat_end) stop 1
  inquire(lun,pos=pos2)
  n = pos2 - pos1
  !print *, n, buffer1(:n)
  if (n /= size(array)+1) stop 2
  if (any(buffer1(:size(array)) /= array)) stop 3
  close(lun)
  
  !! Read into pointer character buffer -- THIS READS RANDOM GARBAGE
  open(newunit=lun,file='junk',action='read',access='stream',iostat=ios)
  inquire(lun,pos=pos1)
  allocate(buffer2(100))
  read(lun,iostat=ios) buffer2
  if (ios /= iostat_end) stop 4
  inquire(lun,pos=pos2)
  n = pos2 - pos1
  !print *, n, buffer2(:n)
  if (n /= size(array)+1) stop 5
  if (any(buffer2(:size(array)) /= array)) stop 6
  close(lun)

end program

 

Labels (2)
0 Kudos
2 Replies
Barbara_P_Intel
Moderator
423 Views

Yes, I see the same "6" as output with internal versions of the ifx and ifort. I filed a bug report, CMPLRLLVM-53862. I'll let you know when I know more.



0 Kudos
Barbara_P_Intel
Moderator
155 Views

Good news! This bug is fixed in the preview of the 2024.2.0 compiler. Look for that release in mid-2024.

 

0 Kudos
Reply