Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
The Intel sign-in experience has changed to support enhanced security controls. If you sign in, click here for more information.
27789 Discussions

Compiler BUG - compile time initialization of a vector



we recently found a strange bug using the Intel Fortran compiler where a simple integer vector vec is initialized by some computed values.
These computed values are wrong if its computation involves an addition (+1) and a power (**2) AND on the syntax of the initialization of a second vector vec2: "vec2 = 1" or "vec2(:) = 1"

For better understanding, here we paste a working minimal code snippet that produces a wrong result:

  1. program main
  2.    implicit none
  3.    integer, parameter :: a = 2
  4.    integer, parameter :: b = 1
  5.    integer, dimension(4) :: vec = (/ a, b, a*(b+1), a*(b+1)**2 /)
  6.    integer, dimension(3) :: vec2
  7.    vec2(:) = 1
  8.    write(*,*) "what to expect:", (/ a, b, a*(b+1), a*(b+1)**2 /)
  9.    write(*,*) "what we got:   ", vec
  10.    ! output should be: 2 1 4 8
  11.    write(*,*) vec2
  12. end program main

Here the expression a*(b+1)**2 in line 5 is miscalculated. Obviously it should be 2*(1+1)**2=8. But the result is 2.
The mysterious thing is if we change line 7 to vec2 = 1 the correct result comes out.
If we compare the assembly files between these 2 versions of the code the only difference is the precomputed value of the 4th element of vec!

We cannot see any other reason for this strange behaviour despite it being a BUG.

We had reproduced this bug on 2 different PCs with 2 different version of ifort. With gfortran both versions produce the same, correct result.

Can anyone of you reproduce this? Both versions are attached to this post.


0 Kudos
1 Reply

I can reproduce the behavior you're seeing, and it's bizarre.

I've created an internal tracking report for it; the number is DPD2000248903.

Someone should report back here when we have a fix.

                 -- Lorri