problem with allocatable character variable inside a polymorphic linked list

problem with allocatable character variable inside a polymorphic linked list

Portrait de Juan Pablo S.

Hello. I noticed this problem with an allocatable character variable when used inside a polymorphic linked list compiled with  ifort version 13.0.1  . The output is the following. 

First output: allocatable character

D

D

D

D

Second output: assigned length character

A

B

C

D

What am I doing wrong?

 program main
 implicit none
 type :: linked_list
 class(linked_list), pointer :: prev
 class(linked_list), pointer :: next
 class(*), pointer :: data
 end type
 type :: named_type_A
 character(:),allocatable :: name
 end type
 type :: named_type_B
 character(len=1) :: name
 end type
 type(named_type_A),target :: t_a
 type(named_type_B),target :: t_b
 class(*),pointer :: polydata
 class(linked_list),pointer :: listA, listB
 character(len=1),dimension(4) :: ch
 integer :: i_list
 ch=(/'A', 'B', 'C ', 'D'/)
 ! FIRST OUTPUT CORRECT 
 print*, 'First output: allocatable character'
 polydata=>t_a
 allocate(listA)
 do i_list = 1, 4
 t_a%name=ch(i_list)
 allocate(listA%data,source=polydata)
 allocate(listA%next)
 listA%next%prev=>listA
 listA=>listA%next
 end do
 do while(associated(listA%prev))
 listA=>listA%prev
 end do
 do i_list = 1, 4
 select type(q=>listA%data)
 type is(named_type_A)
 print*, q%name
 end select 
 listA=>listA%next
 end do
 print*, 'Second output: assigned length character' 
 polydata=>t_b
 allocate(listb)
 do i_list = 1, 4
 t_b%name=ch(i_list)
 allocate(listb%data,source=polydata)
 allocate(listb%next)
 listb%next%prev=>listb
 listb=>listb%next
 end do
 do while(associated(listB%prev))
 listB=>listB%prev
 end do
 do i_list = 1, 4
 select type(q=>listB%data)
 type is(named_type_B)
 print*, q%name
 end select 
 listB=>listB%next
 end do
 end program

6 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.
Portrait de Steve Lionel (Intel)

I don't think you are doing anything wrong, but I need to investigate further. My guess is that this is a compiler bug,  I will let you know.

Steve
Portrait de Steve Lionel (Intel)

I can reproduce this, though the synmptoms vary depending on how and on which platform I build it. I have escalated the problem as issue DPD200240765. Thanks for the nice example.

Steve
Portrait de Steve Lionel (Intel)

We have fixed this for a release later this year.

Steve
Portrait de Steve Lionel (Intel)

The developer who worked on this just sent me an additional note...

There is actually a fairly significant bug in this code.  In both case 1 and case 2, the first list element never nullifies its prev field, and then relies on that field being NULL later on in the code: 

do while(associated(listA%prev))
listA=>listA%prev
end do 

To fix this, after the line:   

allocate(listA)

there needs to be added the line:   

nullify(listA%prev)

and after the line:   

allocate(listB)

there needs to be added the line:   

nullify(listB%prev)

This is actually the cause of several of the manifestations of the problem reported in the original description.

Steve
Portrait de Juan Pablo S.

Sorry for this unwanted bug. But in the original code in which I first noticed this problem,  the  line 4 of the example actually was

class(linked_list), pointer :: prev=>null()

Thanks,

Juan

Connectez-vous pour laisser un commentaire.