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

Bug report for ifort 14.0 and 15.0

Martin_R_3
Beginner
1,353 Views

When compiling the attached testcase using ifort "bugrep.f90" and calling the generated executable via "./a.out blah blah blah", the output is:

 nargs:           3
 tmp=blah
 stored=blah
 tmp=blah
 stored=blah
 tmp=blah
 stored=blah
 size(args)=           0


However, I'd expect an output of:

 nargs:           3
 tmp=blah
 stored=blah
 tmp=blah
 stored=blah
 tmp=blah
 stored=blah
 size(args)=           3
 blah
 blah
 blah

This is what recent versions of GNU Fortran give me. This looks like a bug in the Intel compiler.

Test case:

module mod
implicit none

type,public :: string
  character (len=:), allocatable :: s
end type

contains

function getCmdLine()
  type(string),dimension(:),allocatable :: getCmdLine
  character(len=1024) :: tmp

  integer m
print *,"nargs:", command_argument_count()
  allocate(getCmdLine(command_argument_count()))
  do m=1,command_argument_count()
    call get_command_argument(m, tmp)
print *,"tmp=",trim(tmp)
    getCmdLine(m)%s=trim(adjustl(tmp))
print *,"stored=",getCmdLine(m)%s
  end do
end function

end module

program test
use mod
implicit none
type(string),allocatable::args(:)
integer i

args=getCmdLine()
print *,"size(args)=",size(args)
do i=1,size(args)
print *,args(i)%s
enddo

end program

 

0 Kudos
5 Replies
Lorri_M_Intel
Employee
1,353 Views

By default, Intel Fortran does not allocate the left-hand-side of an assignment, except for deferred-length strings.
(You saw that inside routine getCmdLine)

If you use the command line "-assume realloc_lhs"  or "-standard-semantics" then it will do the allocation.

              --Lorri

 

0 Kudos
Martin_R_3
Beginner
1,353 Views

Thank you, this has resolved the problem!

I must admit that requiring this additional flag is a bit confusing, especially if one already specifies something like "-stand f08". If anything could be done to make this more obvious, it might save a lot of head-scratching ... :)

 

 

0 Kudos
Lorri_M_Intel
Employee
1,353 Views

Yes, we've heard that request before, and we're working on it! 

Glad to hear you're working again --

 

0 Kudos
FortranFan
Honored Contributor III
1,353 Views

Martin R. wrote:

Thank you, this has resolved the problem!

I must admit that requiring this additional flag is a bit confusing, especially if one already specifies something like "-stand f08". If anything could be done to make this more obvious, it might save a lot of head-scratching ... :)

I agree on the "confusing" part, but note -stand is only a diagnostic option - it does not direct the compiler to take any specific action unlike -assume options or -standard-semantics.  I personally would prefer if -standard-semantics were the default, but Intel has its own constraints as explained in this thread:

https://software.intel.com/en-us/forums/intel-fortran-compiler-for-linux-and-mac-os-x/topic/520352

0 Kudos
Kevin_D_Intel
Employee
1,353 Views

To extend Lorri's reply, consideration for making -assume realloc_lhs the default in a future release is being tracked in the internal tracking id, DPD200253547.

0 Kudos
Reply