Intel compiler bug

There is a stupid compiler bug in the Intel Fortran for Linux.

The execute_command_line crash the program if the executable to which the command refers cannot be found, e.g. doesn't exist or is not in the $PATH.

The AHA Model code calls execute_command_line in the call_external function. So it may crash if built with ifort.

Update: The bug is still there in Intel Fortran v.18.0.0.

The bug is posted at the Intel Developer Zone

Test program

Here is a small test program to reproduce the bug:

program buggy

  integer :: int_1 = 0, int_2 = 0
  character(len=:), allocatable :: CMD
  character(len=255) :: msg_out = "unknown"

  CMD="zzz_idontexist"
  call execute_command_line( CMD, wait=.TRUE., exitstat=int_1,   &
                             cmdstat=int_2 ,cmdmsg=msg_out )

  print *, "Report: ", CMD, int_1, int_2, trim(msg_out)

end program buggy

Update: The bug is still here in v. 18.0.1. However, Jim Dempsey provided a workaround. The command line should append a C null string (as is normal in the C language). However, just adding char(0) does not work for some reason. The workaround should add C_NULL_CHAR from ISO_C_BINDING.

program buggy_wrk

  use iso_c_binding, only: C_NULL_CHAR ! <- Workaround
  integer :: int_1 = 0, int_2 = 0
  character(len=:), allocatable :: CMD
  character(len=255) :: msg_out = "unknown"

  CMD="zzz_idontexist"//C_NULL_CHAR    ! <- Workaround
  call execute_command_line( CMD, wait=.true., exitstat=int_1,   &
                               cmdstat=int_2 ,cmdmsg=msg_out )

  print *, "Report: ", CMD, int_1, int_2, trim(msg_out)

end program buggy_wrk

This code with null string works with both Intel and GNU fortran.

The workaround has been introduced into the AHA Model code from SVN r6870.