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

Result of MERGE with polymorphic argument returns wrong dynamic type

Harald1
New Contributor II
1,015 Views

Hello,

ifort/2021.7.0 and earlier versions seem to miscompile the following example:

program p
  implicit none
  type t
     integer :: c
  end type
  type, extends (t) :: t2
     integer :: c2
  end type
  class(t), allocatable :: x, r
  integer :: i = 1
  x = t2(1,-1)
  r = merge (x, x, i == 1)
! r = merge (x, x, .true.)
  select type (z => r)
  type is (t)
    print *,"type is (t) :", z% c
  type is (t2)
    print *,"type is (t2):", z% c, z% c2
  end select
end program p

The resulting code prints:

type is (t) :           1

Note that the NAG compiler 7.1 differs here, it prints:

type is (t2): 1 -1

I would expect the latter as the expected result.

Am I missing something?

Thanks,

Harald

 

0 Kudos
1 Solution
Igor_V_Intel
Employee
947 Views

This problem is reproduced with the latest compiler build and escalated to the development team to be fixed.

Note that gfortran also behaves similar to ifort and ifx.


View solution in original post

0 Kudos
4 Replies
Ron_Green
Moderator
986 Views

This is a good little test.  a few places where the compiler is getting things wrong.  Possible the MERGE intrinsic is returning the parent type(t) instead of t2 as it should.  Also possible the select type is pulling the parent type t instead of the extended type t2 from r.  

We'll get a bug report on this.

Thanks for sending this to us.

0 Kudos
Igor_V_Intel
Employee
948 Views

This problem is reproduced with the latest compiler build and escalated to the development team to be fixed.

Note that gfortran also behaves similar to ifort and ifx.


0 Kudos
Harald1
New Contributor II
942 Views

There is an open bug report with gfortran with a slightly enhanced version of the above test, see

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105371#c8

 

Igor_V_Intel
Employee
655 Views

The bug is fixed in latest Intel Fortran compiler versions, e.g. 2023.1


Reply