Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29285 Discussions

Automatic reallocation causes both compilers problems

NFKirkby
New Contributor I
886 Views

I have the following example code which does not compile with either IFX or IFORT. IFORT hangs with what looks like a memory leak, and IFX says the following

Compiling with Intel® Fortran Compiler 2024.2.1 [Intel(R) 64]...
test_type_type.f90
xfortcom: Fatal: There has been an internal compiler error (C00000FD).
ifx: error #10442: Could not remove 'x64\Debug\test_type_type.obj'

The code is

program test_type_type
implicit none
type :: test_type
    integer :: i = 0
    type( test_type ), allocatable :: next( : )
end type test_type
type(test_type), allocatable :: a( : )
type(test_type) :: b
allocate( a( 1 ) )
a = [ a, b ] ! This automatic reallocation fails
end program test_type_type

Is this automatic reallocation at line 10 'legal' Fortran given that type test_type has an allocatable component also of type test_type?

Thanks in advance

5 Replies
NFKirkby
New Contributor I
837 Views

Interestingly, the following is fine in both compilers:

 

program test_type_type
implicit none
type :: test_type
    integer :: i = 0
    type( test_type ), allocatable :: next( : )
end type test_type
type(test_type), allocatable :: a( : )
type(test_type) :: b
allocate( a( 1 ) )
!a = [ a, b ] ! This auto-allocation fails for IFX
call extend( a, b )
contains
subroutine extend( a, b )
type( test_type ), allocatable, intent( inout ) :: a( : )
type( test_type ), intent( in ) :: b
type( test_type ), allocatable  :: c( : )
call move_alloc( a, c )
allocate( a( size( c ) + 1 ) )
a( 1: size( c ) ) = c
a( size( c ) + 1 ) = b
deallocate( c )
return
end subroutine extend
end program test_type_type

so it looks like [ a, b ] is causing the problem

Shiquan_Su
Moderator
830 Views

Hi,

Would you please point me to any document explaining the syntax of automatic reallocation like:

a = [ a, b ]

I am not very familiar with the expected behavior here.



0 Kudos
andrew_4619
Honored Contributor III
821 Views

I believe I recall a thread discussing issues with this pattern of allocation some time in the last few months. I will do a search.

 

0 Kudos
NFKirkby
New Contributor I
821 Views

Hi,

Yes, this is a very handy feature called automatic reallocation, it is a language standard equivalent of the procedure "extends" in my second post.

The array a must be allocatable

Following a = [ a, b ] a is extended by the contents of b

program demo
implicit none
integer, allocatable :: a(:)
a = [1,2,3,4]
a = [a,5]
print *,a
stop
end program demo

The point of my original post is that automatic reallocation should work for any intrinsic or user-defined type, but I demonstrate a user-defined type for which automatic reallocation does not compile.

Hope this helps

Devorah_H_Intel
Moderator
530 Views

This issue is fixed in the 2025.1 ifx. The fix didn't make it to 2025.0 ifx, which is coming out by the end of this month. 

0 Kudos
Reply