hidden text to trigger early load of fonts ПродукцияПродукцияПродукцияПродукция Các sản phẩmCác sản phẩmCác sản phẩmCác sản phẩm المنتجاتالمنتجاتالمنتجاتالمنتجات מוצריםמוצריםמוצריםמוצרים
Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28985 토론

Automatic reallocation causes both compilers problems

NFKirkby
새로운 기여자 I
634 조회수

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 응답
NFKirkby
새로운 기여자 I
585 조회수

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
중재자
578 조회수

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 포인트
andrew_4619
명예로운 기여자 III
569 조회수

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 포인트
NFKirkby
새로운 기여자 I
569 조회수

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
중재자
278 조회수

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 포인트
응답