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

Potential ifort 19 bug

mani_e204
Beginner
691 Views

I just stumbled upon some weird behavior in ifort 19.1.0.166 on CentOS 7. I am not entirely sure if this is a bug with the compiler or if it's non-standard Fortran so I wanted to ask here. Below is a MWE that illustrates the issue:

program test
   implicit none

   integer, allocatable :: a(:), b1(:), b2(:, :)

   b1 = [2, 1]
   b2 = reshape([1, -1, -2, -3, -4, 2, -5, -6, -7, -8], [5, 2])

   a = b1(b2(1, :))
   write(*, *) shape(a), "|", a
end program test

What's important is that the output of this program depends on whether one uses runtime checks (-C) or not. Basically, we use b2(1, (which is just [1, 2]) to index b1 (which should yield [2, 1]) to automatically allocate a to [2, 1]. So the expected output should be:

           2 |           2           1

However, after enabling runtime checks, the output changes to:

           1 |           2

 Is there something wrong with the code? I do believe all of this should be valid Fortran (2003).

0 Kudos
5 Replies
Arjen_Markus
Honored Contributor I
665 Views

I would say it is conforming. I can also confirm that the program works with Intel Fortran 2018, with and without -C (or -check:all). I get the same answer. gfortran also accepts it and produces the same output.

0 Kudos
Steve_Lionel
Honored Contributor III
644 Views
0 Kudos
Barbara_P_Intel
Moderator
596 Views

I traced the issue down to -check shape.  It's embedded in -C.  

Here's a workaround

+ ifort -C -check noshape c.f90
+ a.out
           2 |           2           1

I filed a bug on your behalf,  CMPLRIL0-33624. I'll let you know when there's a fix.

0 Kudos
mani_e204
Beginner
583 Views

Great! Thanks a lot, I appreciate it.

0 Kudos
Barbara_P_Intel
Moderator
490 Views

This is fixed in the latest compiler release, 2021.2.0.  It was made available last week.   Please give it a try.

$ GO
ifort (IFORT) 2021.2.0 20210228
Copyright (C) 1985-2021 Intel Corporation.  All rights reserved.

+ ifort -C c.f90
+ a.out
           2 |           2           1
+ ifort -C -check noshape c.f90
+ a.out
           2 |           2           1
+ ifort -check shape c.f90
+ a.out
           2 |           2           1

 

0 Kudos
Reply