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

User defined IO - runtime error with /check:pointer and /libs:dll

johnyb61
Novice
474 Views

Hello,

with ifx 2024.0.0 on Windows 10 the following code:

module type_test
    implicit none
    private
    public T_TEST
    type T_TEST
        integer    :: vlist_val
    contains
        procedure, private :: r_fmt_idc
        generic            :: read(formatted)  => r_fmt_idc
    end type
    contains
        subroutine r_fmt_idc(dtv, unit, iotype, vlist, iostat, iomsg)
            class(T_TEST),      intent(inout)   :: dtv
            integer,            intent(in)      :: unit
            character(len=*),   intent(in)      :: iotype
            integer,            intent(in)      :: vlist(:)
            integer,            intent(out)     :: iostat
            character(len=*),   intent(inout)   :: iomsg
            dtv%vlist_val = vlist(1)
            iostat = 0
        end subroutine
end module type_test
 
program ifx_001
    use type_test
    character(len=5) :: s
    type(T_TEST) t
 
    read(s, fmt="(DT(5))") t
    print *, t%vlist_val
end program

when compiled with
ifx /check:pointer /libs:dll ifx_001.f90

produces this runtime error:

forrtl: severe (408): fort: (7): Attempt to use pointer VLIST when it is not associated with a target
Image              PC                Routine            Line        Source
libifcoremd.dll    00007FFDE104E09C  Unknown               Unknown  Unknown
ifx_001.exe        00007FF760311055  Unknown               Unknown  Unknown
libifcoremd.dll    00007FFDE10CC82D  Unknown               Unknown  Unknown
libifcoremd.dll    00007FFDE10CD529  Unknown               Unknown  Unknown
libifcoremd.dll    00007FFDE109862F  Unknown               Unknown  Unknown
ifx_001.exe        00007FF7603111B1  Unknown               Unknown  Unknown
ifx_001.exe        00007FF76031121B  Unknown               Unknown  Unknown
ifx_001.exe        00007FF760311520  Unknown               Unknown  Unknown
KERNEL32.DLL       00007FFE9BB37344  Unknown               Unknown  Unknown
ntdll.dll          00007FFE9BD826B1  Unknown               Unknown  Unknown

Full compiler and Windows version:

Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2024.0.0 Build 20231017

Windows 10 22H2 Version 10.0.19045.4170

With only one of the compile options the code runs fine. The example code is of course a minimal example, the problem occurs in a large application I am migrating from VS2015/Ifort 18.0 to VS2022/ifx.

The problem does not occur with IFort 18.0.5

Out of curiosity I also compiled with Ifort 2021.11.0 and the problem occurs also

Is this a bug in the runtime or inadequate usage of the options by me ?

 

0 Kudos
1 Solution
johnyb61
Novice
365 Views

Hi Barbara, 

after reading your post I got the suspicion that something in my setup must be wrong. And actually, using Sysinternal Process Explorer and a read *,s statement to halt my program before the crash, I can see that libifcoremd.dll and libmmd.dll are taken from C:\Program Files (x86) \Intel\oneAPI\intelPython\latest\Library\bin instead of C:\Program Files (x86)\Intel\oneAPI\compiler\2024.0\bin.

I was using the setvars.bat script in C:\Program Files (x86)\Intel\oneAPI which seems not to be the right one. I think this has to do with the new layout of directories introduced with the 2024.0 release (and me not reading all the doc.)

By running the oneapi-vars script from C:\Program Files (x86)\Intel\oneAPI\2024.0 and compiling and running from within that environment, everything works fine.

Thanks for your help!

View solution in original post

6 Replies
FortranFan
Honored Contributor II
462 Views

@johnyb61 wrote:

..

Is this a bug in the runtime or inadequate usage of the options by me ?


The latter.

You need to do "defensive programming" here.  An option you can consder is to guard the reference to vlist by taking advantage of the fact Fortran allows zero-sized arrays:

if ( size(vlist) > 0 ) then
   dtv%vlist_val = vlist(1)
end if

You can also employ the "iotype" received argument for further defensive progrmaming.

Note when the caller consumes the derived-type defined IO with list-directed or namelist formatting, the callee can expect vlist to be treated as zero-sized array.

0 Kudos
johnyb61
Novice
455 Views

But in my example with format DT(5) vlist should not be empty, it should be [5].

When compiled without check:pointer the program prints 5, which is the value of vlist(1) and the expected result.

But with the given compiler options it either becomes empty or the runtime check checks the wrong things. 

 

0 Kudos
johnyb61
Novice
454 Views

Just to be certain, i tried to use your code and the problem remains because size(vlist) is 1 (as you can see if you add a print *, size(vlist)  inside your if block) but then accessing the value of the first element triggers the runtime error.

0 Kudos
Barbara_P_Intel
Moderator
390 Views

@johnyb61, this is weird. I cannot reproduce your output with the same version of ifx.

Q:\tmp>ifx /check:pointer /libs:dll type_test.f90
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2024.0.0 Build 20231017
Copyright (C) 1985-2023 Intel Corporation. All rights reserved.

Microsoft (R) Incremental Linker Version 14.38.33130.0
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:type_test.exe
-subsystem:console
type_test.obj

Q:\tmp>type_test.exe
           5

I'm on Windows 11 with VS 2022 Version 17.8.1.

 

0 Kudos
johnyb61
Novice
366 Views

Hi Barbara, 

after reading your post I got the suspicion that something in my setup must be wrong. And actually, using Sysinternal Process Explorer and a read *,s statement to halt my program before the crash, I can see that libifcoremd.dll and libmmd.dll are taken from C:\Program Files (x86) \Intel\oneAPI\intelPython\latest\Library\bin instead of C:\Program Files (x86)\Intel\oneAPI\compiler\2024.0\bin.

I was using the setvars.bat script in C:\Program Files (x86)\Intel\oneAPI which seems not to be the right one. I think this has to do with the new layout of directories introduced with the 2024.0 release (and me not reading all the doc.)

By running the oneapi-vars script from C:\Program Files (x86)\Intel\oneAPI\2024.0 and compiling and running from within that environment, everything works fine.

Thanks for your help!

Barbara_P_Intel
Moderator
344 Views

You're welcome! I'm glad you found the solution!

Good sleuthing!

 

0 Kudos
Reply