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

Allocation of derived-type with allocatable component in a block fails

martinmath
New Contributor II
1,019 Views

Allocating an array of a derived-type which contains an allocatable component within a block statement fails for both ifort as well as ifx (recent 2024 release, linux). No compile options required.

program alloc_block
implicit none

type :: int_scalar
   integer :: i = 0
end type int_scalar

type :: int_alloc
   integer, allocatable :: i
end type int_alloc

type :: string
   character(len=:), allocatable :: c
end type string

type(int_scalar), dimension(:), allocatable :: a
type(int_alloc), dimension(:), allocatable :: b
type(string), dimension(:), allocatable :: c
integer, dimension(:), allocatable :: d

block
   allocate(a(1:1))
   allocate(b(1:1))
   allocate(c(1:1))
   allocate(d(1:1))
end block
print *, allocated(a), allocated(b), allocated(c), allocated(d)

end program alloc_block

 

6 Replies
Barbara_P_Intel
Employee
989 Views

Can you please be more specific about the failure? compile time? runtime?

What message do you get?

 

0 Kudos
JohnNichols
Valued Contributor III
982 Views
0 Kudos
martinmath
New Contributor II
958 Views

Sorry, I forgot that. Allocation fails for "b" and "c" and I get the output "T F F T" instead of "T T T T". All four variables should be allocated at the final print statement.

I just checked the stat, which is zero (i.e. allocation succeeded). Below is the same code but with additional diagnostic output, and it seems that within the block, all four variables are indeed allocated, but "b" and "c" get deallocated at end of block statement. I also thought that "dimension(:)" for b and c is necessary, but it also fails if b and c are declared without that, i.e. as scalar values.

program alloc_block

implicit none

type :: int_scalar
   integer :: i = 0
end type int_scalar

type :: int_alloc
   integer, allocatable :: i
end type int_alloc

type :: string
   character(len=:), allocatable :: c
end type string

type(int_scalar), dimension(:), allocatable :: a
type(int_alloc), dimension(:), allocatable :: b
type(string), dimension(:), allocatable :: c
integer, dimension(:), allocatable :: d
integer :: stat

block
   allocate(a(1:1), stat=stat)
   print *, allocated(a), stat
   allocate(b(1:1), stat=stat)
   print *, allocated(b), stat
   allocate(c(1:1), stat=stat)
   print *, allocated(c), stat
   allocate(d(1:1), stat=stat)
   print *, allocated(d), stat
end block
print *, allocated(a), allocated(b), allocated(c), allocated(d)

end program alloc_block

 

0 Kudos
JohnNichols
Valued Contributor III
931 Views

Now that you have explained it better, yes I see the error in Windows.  

Interesting really, clearly a bug in Intel Fortran. 

0 Kudos
Barbara_P_Intel
Employee
909 Views

Good news! This issue is fixed in the next minor compiler release due about the end of Q1 2024. The issue is fixed for both ifx and ifort.

ifx mm.f90
a.out
 T T T T

ifx mm2.f90
a.out
 T           0
 T           0
 T           0
 T           0
 T T T T

 

Barbara_P_Intel
Employee
563 Views

I confirmed that ifx 2024.1.0 prints the correct output. It was released last week. Please try it out!



0 Kudos
Reply