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

Unexpected crash in namelist read

Harald
Beginner
700 Views

Hello,

the following code leads to a crash in namelist read with the Intel compiler, but not any other Fortran compiler I have access to:

program ifort_nml_bug
  implicit none
  integer     :: n, k(5)
  namelist /nml/ n, k
  k = -1
  n = -1
  read(*,nml=nml)
  print *, k
end program ifort_nml_bug

The namelist input file:

&nml
k =
n = 2
/

The demo:

% ifort -g -traceback ifort_nml_bug.f90 && ./a.out < ifort_nml_bug.nml
forrtl: severe (17): syntax error in NAMELIST input, unit -4, file /proc/24888/fd/0, line 3, position 3
Image              PC        Routine            Line        Source             
a.out              0806F9D0  Unknown               Unknown  Unknown
a.out              0804ED8B  Unknown               Unknown  Unknown
a.out              0804A06B  MAIN__                      7  ifort_nml_bug.f90
a.out              08049F66  Unknown               Unknown  Unknown

This occurs with ifort 14, 15, 16 & 17.0.

Commenting out the line with "n=2" in the namelist input makes the crash go away, so there is some input parsing problem.

Thanks,

Harald

 

0 Kudos
3 Replies
Steve_Lionel
Honored Contributor III
700 Views

The standard says:

The characters in one or more namelist records constitute a sequence of name-value subsequences, each of which consists of an object designator followed by an equals and followed by one or more values and value separators.

Note that it does not say "zero or more". Your input is nonstandard - an implementation may still choose to accept it as an extension.

0 Kudos
Harald
Beginner
700 Views

Steve Lionel (Ret.) wrote:

The standard says:

The characters in one or more namelist records constitute a sequence of name-value subsequences, each of which consists of an object designator followed by an equals and followed by one or more values and value separators.

Note that it does not say "zero or more". Your input is nonstandard - an implementation may still choose to accept it as an extension.

Thanks for pointing this out.

I was looking further down in the standard, where it says:

Each value is either a null value (13.11.3.4), c, r*c, or r*, where c is a literal constant, optionally signed if integer
or real, and r is an unsigned, nonzero, integer literal constant. ...

This gives me plenty of options to specify an empty list for the array k.  However, I am wondering whether the "null value" is also a value in the sense of the text you quoted...  Never mind.

I was surprised by the syntax error in the error message, which points to a parsing problem of the runtime, and which did not show up with the other compilers.  But I agree that fixing the namelist input is the best solution.

Thanks,

Harald

 

0 Kudos
Steve_Lionel
Honored Contributor III
701 Views

The error message is reasonable - the input syntax is invalid. As I said, other compilers can choose to accept this as an extension. There are some things Intel Fortran accepts that other compilers do not.

0 Kudos
Reply