Open bena-nasa opened 3 years ago
A couple of data points. (1) The code compiles and runs without error with NAG 7.0 (7037) with full error checking. and (2) the code crashes under OS X with intel 19.1.3 in pretty much the same ways as described above (which was presumably with intel on linux).
And it is not the trim
per se that is helping. This variant also works
a = key(:idx-1)
b = key(idx+1:)
subcfg = config%at(a, b, rc=status)
Well, it does not crash, but the status is coming back as a nonzero value (looks uninitialized).
OK - the last bit was due to a missing __RETURN__
macro in the topmost function invocation. I'll push a bugfix for that.
I'm fairly convinced that the remaining issue is a defect in the compiler. A standalone reproducer is important - but tedious to implement due to the gFTL component. My temptation is to not bother whittling it down and just shipping it off to Intel.
I think the corner case that is tripping them us is that we are passing a section of a string actual to an unlimited polymorphic dummy. Compilers in general have struggled with passing strings to unlimited polymorphic dummies - presumably due to the need to capture the len
parameter. (Indeed, gfortran seems to have some terrible memory corruption still when doing things like this.)
Quite likely you can avoid the issue entirely with Intel by first putting the slice into a separate variable, or with the trim()
as you've discovered. But since I happen to know what you want the final code to work with GFortran, you may need to actually wrap the arguments with String(<arg>)
which is my workaround for gfortran.
Well, for once a small reproducer was easy to create. I'll submit to Intel shortly:
module bar
implicit none
contains
subroutine foo(arg1, arg2, arg3)
class(*), optional, intent(in) :: arg1
class(*), optional, intent(in) :: arg2
class(*), optional, intent(in) :: arg3
if (present(arg1)) call one(arg1)
if (present(arg2)) call one(arg2)
if (present(arg3)) call one(arg3)
contains
subroutine one(arg)
class(*), intent(in) :: arg
select type (arg)
type is (character(*))
print*,'yes'
class default
print*,'no'
end select
end subroutine one
end subroutine foo
end module bar
program reproducer
use bar
implicit none
character(:), allocatable :: string
string = 'a%b'
call foo(string(:1),string(2:))
!!$ call foo(trim(string(:1)),trim(string(2:)))
end program reproducer
Annoyingly - this still breaks with yaFyaml 1.0 and the latest intel compiler.
I am going to close this ticket. The problem is with the compiler and the workaround must be done in client code. Unfortunate, but will never be fixed (directly) within yaFyaml.
This is with yafmal version 0.4.1 and intel fortran 19.1.3.304 I have this simple program. I'm finding that when trying to retrieve a key I have to trim the string passed to the %at where as if I just take a slice of of the string without the trim it fails despite the trim slice and the slice without the trim seemingly the same, at least according to the result of the print here. Not clear why a trim is needed but seems like a bug in the compiler perhaps?
the input file:
and the traceback
Note line 27 is the 2nd to last line of the program, the 2nd config%at call.