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

Wrong result with defined assignment operator and/or parenthesized expressions and allocatable components

MR
Beginner
278 Views

As discussed also in this thread:

https://groups.google.com/d/msg/comp.lang.fortran/8q2nYfHnZfU/M9FmGgx7AQAJ

ifort produces wrong results with the attached code: the expected output is

 Case A: v1%x =   1.5000000E+00
 Case B: v1%x =   1.5000000E+00
 Case C: v1%x =   1.5000000E+00

while it gives

 Case A: v1%x =   0.0000000E+00
 Case B: v1%x =   0.0000000E+00
 Case C: v1%x =   0.0000000E+00

ifort -V
Intel(R) Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 16.0.0.109 Build 20150815

[Editing the message to remove from the code below some comments which were meant to refer to gfortran and are not relevant here]

module m
 implicit none

 type :: t_a
  real, allocatable :: x
 end type t_a

 interface assignment(=)
  module procedure copy_t_a
 end interface

contains
 
 subroutine copy_t_a(y,x)
  type(t_a), intent(in)  :: x
  type(t_a), intent(out) :: y
   allocate( y%x , source=x%x)
 end subroutine copy_t_a

end module m


program p
 use m
 implicit none

 type(t_a) :: v1

 ! Define v1
 allocate( v1%x )
 v1%x = 1.5
 
 
 v1 = v1
 write(*,*) "Case A: v1%x = ",v1%x ! should print 1.5

 v1 = (v1)
 write(*,*) "Case B: v1%x = ",v1%x ! should print 1.5

 call copy_t_a( v1 , (v1) )
 write(*,*) "Case C: v1%x = ",v1%x ! should print 1.5

end program p

 

0 Kudos
4 Replies
FortranFan
Honored Contributor II
278 Views

@Intel friends,

As implied on the comp.lang.fortran thread, Intel Fortran v16.0.0.110 on Windows may behave differently and it will be great if you can check that out as well.  With /dbglibs (i.e., Debug configuration in Visual Studio), I see an undefined value as a result; perhaps OP has some setting that leads to a zero value.  With Release configuration i.e., no /dbglibs option, the result I see is 1.5 in all 3 cases, regardless of the optimization setting.

0 Kudos
MR
Beginner
278 Views

FortranFan wrote:

@Intel friends,

As implied on the comp.lang.fortran thread, Intel Fortran v16.0.0.110 on Windows may behave differently and it will be great if you can check that out as well.  With /dbglibs (i.e., Debug configuration in Visual Studio), I see an undefined value as a result; perhaps OP has some setting that leads to a zero value.  With Release configuration i.e., no /dbglibs option, the result I see is 1.5 in all 3 cases, regardless of the optimization setting.

Unfortunately (!) I have no access to a Windows machine. From a quick search I have been unable to find an equivalent flag to /dbglibs for the Linux compiler, and my results do not change changing -O level. Is there anything like /dbglibs on Linux?

0 Kudos
Kevin_D_Intel
Employee
278 Views

I will investigate on Linux and Windows and let you know my results.

There is not a /dbglibs equivalent on Linux.

 

 

0 Kudos
Kevin_D_Intel
Employee
278 Views

I reproduced the same results as everyone reported earlier on Linux and Windows. The Linux results are all zero with default options and all opt-levels; no extra options are needed. On Windows, /dbglibs with any opt-level produces the undefined values (the same garbage value for all three cases.) I escalated this to Development.

Thank you for the comp.lang.fortran post link and for following up on this in our forum.

(Internal tracking id: DPD200375945)

0 Kudos
Reply