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

A pointer passed to DEALLOCATE points to an object that cannot be deallocated

pwl_b
Novice
7,500 Views

Compiling (with ifort 13.1.1) and executing the following code

[fortran]

module tt

  type :: t
  end type t

  type :: t1
     class(t), pointer :: tp
   contains
     procedure :: set
     procedure :: unset
  end type t1

contains

  function t_new() result(r)
    type(t), pointer :: r
    allocate(r)
  end function t_new

  subroutine set(a, tp)
    class(t1) :: a
    class(t), target :: tp
    a%tp => tp
  end subroutine set

  subroutine unset(a)
    class(t1) :: a
    print *, "Dealocating"
    deallocate(a%tp)
    print *, "Deallocated"
  end subroutine unset

end module tt


program test

  use tt

  type(t1) :: a

  call a%set(t_new())
  call a%unset()

end program test

[/fortran]

I get

[plain]

 Dealocating
forrtl: severe (173): A pointer passed to DEALLOCATE points to an object that cannot be deallocated
Image              PC                Routine            Line        Source             
pointer            000000000046D7AE  Unknown               Unknown  Unknown
pointer            000000000046C246  Unknown               Unknown  Unknown
pointer            0000000000424FC2  Unknown               Unknown  Unknown
pointer            00000000004068BB  Unknown               Unknown  Unknown
pointer            00000000004050E6  Unknown               Unknown  Unknown
pointer            0000000000402C57  Unknown               Unknown  Unknown
pointer            0000000000402B3C  Unknown               Unknown  Unknown
libc.so.6          00007FB324690A15  Unknown               Unknown  Unknown
pointer            0000000000402A39  Unknown               Unknown  Unknown

[/plain]

but using gfortran yields

[plain]

 Dealocating
 Deallocated

[/plain]

Is this a bug?

Best,

Paweł Biernat

24 Replies
Tripp
Beginner
1,132 Views

Halfway through 2022 and this bug still exists. I just lost a whole day trying to figure it out before I finally found this thread. Can we please get a fix?

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,127 Views

Just for kicks, try:

  deallocate((a%tp)) ! enclose in ()

 

and/or

class(t), pointer :: tp_temp

...

tp_temp => a%tp

deallocate(tp_temp)

nullify(a%tp)

 

Jim Dempsey

0 Kudos
Ron_Green
Moderator
1,091 Views

This issue appears to have fallen off the radar sometime back. I have re-escalated this issue to our developers. Bug ID is: CMPLRIL0-21046

0 Kudos
Barbara_P_Intel
Employee
888 Views

This issue is fixed in the current Fortran compilers that were released earlier this week. The compilers are part of oneAPI HPC Toolkit 2023.2.

Please try it.

I just noticed how old this is. It took us a while.



0 Kudos
Reply