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

Incorrect handling of EQUIVALENCE in ifx

Simon_Richards
Beginner
292 Views

The following example code gives incorrect results with ifx version 2022.1.0

PROGRAM ifx_equiv

  IMPLICIT NONE
  
  REAL :: a(5) = [1.0, 2.0, 3.0, 4.0, 5.0]
  REAL :: b(5) = [6.0, 7.0, 8.0, 9.0,10.0]
  REAL :: c(10)
  
  EQUIVALENCE (a(1), c(1))  
  EQUIVALENCE (b(1), c(6))
  
!  DATA a /1.0, 2.0, 3.0,  4.0,  5.0/
!  DATA b /6.0, 7.0, 8.0,  9.0, 10.0/
  
!  a = [1.0, 2.0, 3.0, 4.0, 5.0]
!  b = [6.0, 7.0, 8.0, 9.0,10.0]
 
  WRITE(*,'("a  = ", 5F5.1)') a
  WRITE(*,'("b  = ", 5F5.1)') b
  WRITE(*,'("c  = ", 10F5.1)') c 
  
END PROGRAM ifx_equiv

The (incorrect) output when compiled with ifx is:

a  =   1.0  2.0  3.0  4.0  5.0
b  =   0.0  0.0  0.0  0.0  0.0
c  =   1.0  2.0  3.0  4.0  5.0  0.0  0.0  0.0  0.0  0.0

The (correct) output when compiled with ifort or gfortran is:

a  =   1.0  2.0  3.0  4.0  5.0
b  =   6.0  7.0  8.0  9.0 10.0
c  =   1.0  2.0  3.0  4.0  5.0  6.0  7.0  8.0  9.0 10.0

 If you replace the default initialization of the arrays with the commented out DATA statements the same error occurs. However, if you explicitly initialize the arrays, as in the commented out lines 15 and 16, then the error does not occur.

This looks to me like an ifx compiler bug.

I realize that EQUIVALENCE is an obsolete language feature which can be unsafe and should be avoided. This minimum example is based on a legacy routine in a production code which was found to give incorrect results with the ifx compiler as a consequence of this error.    

0 Kudos
3 Replies
Steve_Lionel
Black Belt Retired Employee
271 Views

Still fails in ifx 2022.2.0.

Ron_Green
Moderator
258 Views

We'll get a bug report on this.  Thanks for catching it.

 

 

Devorah_H_Intel
Moderator
123 Views

 This was fixed in future release.

ifort equiv.f90 -o eq  
 $ ./eq
a  =   1.0  2.0  3.0  4.0  5.0
b  =   6.0  7.0  8.0  9.0 10.0
c  =   1.0  2.0  3.0  4.0  5.0  6.0  7.0  8.0  9.0 10.0
 $ ifx equiv.f90 -o eq  
 $ ./eq
a  =   1.0  2.0  3.0  4.0  5.0
b  =   6.0  7.0  8.0  9.0 10.0
c  =   1.0  2.0  3.0  4.0  5.0  6.0  7.0  8.0  9.0 10.0
 $
Reply