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

When I use block and derived data type at same time, some errors occurred. This may be a bug?

wang1
Beginner
297 Views

When I use block and derived data type at same time, some errors occurred.

 

This is the code, the correct code is

module Test
implicit none
type :: s
    integer,allocatable,dimension(:)::x
end type s
end module Test
 
program main
use Test
implicit none
type(s),allocatable::a(:)
type(s)::b
integer::i
i=2
if (== 1) then
    block
        !allocate (a(3))
    end block
else
    block
        allocate (a(5)) 
        do i = 15
            a(i)%x=[i]
        end do
        b = a(2)
        write (**)
    end block
end if
end program main

 and we get that the b%x is a array with size 1, and value is 2. As the figure show

wang1_1-1638089949861.png

 

But if we uncomment the allocate (a(3)) statement, we get 

wang1_2-1638089985914.png

the b%x is Undefined address, but the allocate (a(3)) statement should not run , and doesn't affect the result of b. So I dont't know if it's a bug of ifort.

Labels (2)
0 Kudos
1 Solution
Steve_Lionel
Black Belt Retired Employee
267 Views

Yes, it's a bug. With the first allocate commented out, the compiler is deallocating array a at the end of the second block, which it should do only if it was declared within that block (it wasn't). With the first allocate uncommented, the compiler doesn't do the bad deallocate.

View solution in original post

1 Reply
Steve_Lionel
Black Belt Retired Employee
268 Views

Yes, it's a bug. With the first allocate commented out, the compiler is deallocating array a at the end of the second block, which it should do only if it was declared within that block (it wasn't). With the first allocate uncommented, the compiler doesn't do the bad deallocate.

Reply