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

Compiler bug (?) with type-bound procedures and pointers

MDK
Beginner
976 Views
[plain]module ifort_bug_mod

    implicit none
    
    type :: foo_t
        integer :: i = 999
    contains
        procedure :: write_foo
    end type
  
    type :: bar_t
        type(foo_t), pointer :: pfoo => null()
    end type
  
        
contains

    subroutine write_foo(this)
        implicit none
        class(foo_t), intent(in) :: this
        write (*, *) this%i
    end subroutine
    
end module


program ifort_bug

    use ifort_bug_mod
    
    implicit none
    
    type(foo_t), target :: foo
    type(foo_t), pointer :: pfoo
    type(bar_t) :: bar
    
    pfoo => foo
    bar%pfoo => foo
    
    call write_foo(pfoo)      ! ok
    call write_foo(bar%pfoo)  ! ok
    call pfoo%write_foo()     ! ok
    call bar%pfoo%write_foo() ! error
    
end program[/plain]

If I try to access a type-bound procedure using a pointer to the type that is itself a type component, I get garbage results as if the target of the pointer is undefined. Calling the type-bound procedure through a plain pointer produces the correct result, as does calling the procedure as a regular procedure--e.g. 'sub(foo)' rather than 'foo%sub()'--using either the plain pointer or a pointer that is a type component. I'm using 11.1.051.
0 Kudos
5 Replies
abhimodak
New Contributor I
976 Views
Some additional observations that may help Intel:

If I watch the value of this%i in the debugger, I see that for ALL the calls the value is garbage. For the first three calls where the printed answer looks ok, the debugger shows this%i = 4944540 while for the last call it shows 4944564.

Similar to this, the "value" of the procedure write foo is also same (#004B7288) while being different (#004B7290). Before the call is made for all combination, %i and %writefoo are 999 and #004D5000.

Of course, I don't think that the specifics are important here but it just hightlights that even though the printed values are correct for first three cases not all is good on the debugger level.

Abhi
0 Kudos
Steven_L_Intel1
Employee
976 Views

Thanks - we'll take a look.
0 Kudos
Steven_L_Intel1
Employee
976 Views
This looks similar to issue DPD200140796 but I'm not yet certain.
0 Kudos
Steven_L_Intel1
Employee
976 Views
Yes, it is the same. It is fixed in our sources but I do not yet know when it will appear in a compiler near you. I will post here when I have more information.
0 Kudos
Steven_L_Intel1
Employee
976 Views
This issue is fixed in 11.1 Update 6, available now.
0 Kudos
Reply