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

Unlimited polymorphic pointer rank remapping bug(?)

Neil_Carlson
Beginner
508 Views

I was experimenting with pointer rank remapping, and discovered some unexpected results when the pointer and target were unlimited polymorphic.  I'm not certain about the code though -- feels a bit sketchy -- however I wasn't able to find anything in the 2003 standard that excludes a polymorphic target and pointer from pointer rank remapping.  The compiler doesn't complain -- only the results are wrong/unexpected.   Here's the code

program main

  class(*), allocatable, target :: array(:)
  class(*), pointer :: ptr(:,:)
  
  allocate(array, source=[1,2,3,4])
  
  ptr(1:2,1:2) => array
  
  select type (ptr)
  type is (integer)
    print *, 'expect 1 2 3 4:', ptr
    print *, 'expect 1 3:', ptr(1,:)
    print *, 'expect 2 4:', ptr(2,:)
    print *, 'expect 1 2:', ptr(:,1)
    print *, 'expect 3 4:', ptr(:,2)
  end select
  
end program

The results with the 14.0.2 compiler are:

 expect 1 2 3 4:           1           2           3           4
 expect 1 3:   538976288   538976288
 expect 2 4:   538976288   538976288
 expect 1 2:           1           2
 expect 3 4:           1           2

Is the compiler generating bad code, or is the code not standard and the compiler just isn't complaining (kind of a bug too)?  Thoughts?

0 Kudos
3 Replies
FortranFan
Honored Contributor III
508 Views

Looks like a bug in Intel 14.0.2 compiler version - have you tried in Intel 2015 Beta version?  The program runs as expected in gfortran 4.9.

0 Kudos
Kevin_D_Intel
Employee
508 Views

I do not know whether the program is fully conforming and will lean on Development (or others in the Forum) for help regarding that. I did confirm the unexpected results occur when using the 14.0 and  current 2015 Beta compilers and reported the issue to Development (see internal tracking id below) for further investigation and will let you know what I hear back.

(Internal tracking id: DPD200357656)

0 Kudos
Steven_L_Intel1
Employee
508 Views

The code is standard-conforming.

0 Kudos
Reply