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

run-time error from mixed Fortran/C program using CFI_allocate if "-check all" used

Fortran4Me
Beginner
297 Views

The attached demo of using CFI_allocate to allocate an array in C and return it to the calling Fortran program sometimes results in the run-time error Attempt to fetch from allocatable variable ARRAY when it is not allocated.   

commands:

icc -c demo.c

ifort demo.o demo_main.f90 -o demo.exe

is OK but

ifort -check all demo.o demo_main.f90  -o demo.exe

causes the run-time error.

Details: OS is Mac 10.13.6; ifort 2021.1 Beta 20201112.

Thanks for providing the Intel Fortran compiler!

0 Kudos
1 Solution
Steve_Lionel
Black Belt Retired Employee
271 Views

There are (at least) two things wrong here. The first is that the compiler should not be doing pointer/allocatable checks on the call to "demo", since the array argument is allocatable and intent(inout). (I also tested with "out" and got the same behavior.) This is not a "data object reference" (F2018 3.120.1) to array and it's perfectly acceptable to pass an unallocated array to an intent(inout) allocatable dummy. The only time such a diagnostic would be warranted is if the dummy was declared intent(in).

The second, which may cause problems down the road, is that the compiler is not filling in the Intel-only flags and reserved fields in the C descriptor, leaving them as whatever they had before (in my test, hex CCCCCCCC.) This will trip up other parts of the code that expect the flags, at least, to start out as zero.

 

View solution in original post

3 Replies
Steve_Lionel
Black Belt Retired Employee
272 Views

There are (at least) two things wrong here. The first is that the compiler should not be doing pointer/allocatable checks on the call to "demo", since the array argument is allocatable and intent(inout). (I also tested with "out" and got the same behavior.) This is not a "data object reference" (F2018 3.120.1) to array and it's perfectly acceptable to pass an unallocated array to an intent(inout) allocatable dummy. The only time such a diagnostic would be warranted is if the dummy was declared intent(in).

The second, which may cause problems down the road, is that the compiler is not filling in the Intel-only flags and reserved fields in the C descriptor, leaving them as whatever they had before (in my test, hex CCCCCCCC.) This will trip up other parts of the code that expect the flags, at least, to start out as zero.

 
Fortran4Me
Beginner
228 Views

Thanks for your detailed reply.

Will this information reach the compiler developers, or is there somewhere that I should file a bug report?

Steve_Lionel
Black Belt Retired Employee
192 Views

It might, if an Intel support engineer notices this and picks it up. If you don't have a support license, reports through the Online Service Center would likely get closed. (I do not agree with this policy for simple bug reports.)

 
Reply