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

wrong result traversing linked list with ifort 12

roper
Beginner
501 Views

using:

ifort (IFORT) 12.0.0 20101006

In this test case, I create a linked list of 4 elements with polimorphic objects, and when I traverse it, it only prints 3 of them.
using an alternate advance instruction, it shows all 4 objects, but it should work in both cases.

the output is:

---
35082336 0 0
35082496 0 0
35082656 0 0
---
35082336 0 0
35082496 0 0
35082656 0 0
35082816 0 0
---

that has 3 + 4 lines, but it should have 4 + 4 lines. the exact numbers shown may differ.

this is the attachment:
http://software.intel.com/file/m/32517
 

0 Kudos
3 Replies
Ron_Green
Moderator
501 Views
yes, looks like a bug. I've modified the source a little to make it more clear where the bug is happening:

program pe

type, abstract :: t
integer :: i = 1
class(t), pointer :: next => null()
integer :: j = 2
end type

type, extends(t) :: u
integer :: k = 3
end type

type, extends(t) :: v
integer :: l = 4
end type

class(t), pointer :: ini => null()
class(t), pointer :: p => null()
class(t), pointer :: temp => null()

allocate(u :: ini)
allocate(v :: ini%next)
allocate(u :: ini%next%next)
allocate(v :: ini%next%next%next)

print *, '---'

p => ini

do while (associated(p))
print *, "current element", loc(p),"next associated?-->",associated(p)
print *, " traverse to next element "
p => p%next
print *, "next element", loc(p),"next associated?-->",associated(p)
print *, " "
enddo

print*, "exited loop - why?"
print *, '---'

p => ini

do while (associated(p))
print *, "current element", loc(p),"next associated?-->",associated(p)
print *, " traverse to next element "
temp => p%next
p => temp
print *, "next element", loc(p),"next associated?-->",associated(p)
print *, " "
enddo

print *, '---'

deallocate(ini%next%next%next)
deallocate(ini%next%next)
deallocate(ini%next)
deallocate(ini)

end program

I'll start a bug report
0 Kudos
Ron_Green
Moderator
501 Views
bug report ID is DPD200163749

btw - this is a very clean and nice example of using F03 to create linked lists! Great use of F03 features.

ron
0 Kudos
Ron_Green
Moderator
501 Views

this bug was fixed some time ago.  marking it closed, thanks for sending this to us!

0 Kudos
Reply