An error raised by `ifort -check shape`

I have encountered a strange error raised by ifort -check shape with ifort (IFORT) 2021.2.0 20210228. Here is a minimal working example.

! testshape.f90
program testshape
implicit none
integer :: a(1, 2)
a(:, :) = a(:, :)  ! This line is OK. Benchmark for the erroneous line.
a(:, 1:2) = a(:, 1:2)  ! This line is OK. Benchmark for the erroneous line.
a(:, [1, 2]) = a(:, [1, 2])  ! Do nothing ..., but it triggers the error.
end program testshape

Name this code as testshape.f90, and then compile it. Here is what happens on my machine (Ubuntu 20.04).

$ ifort -check shape testshape.f90
testshape.f90(7): error #5581: Shape mismatch: The extent of dimension 1 of array A is 1 and the corresponding extent of array <RHS expression> is 2
a(:, [1, 2]) = a(:, [1, 2])  ! Do nothing ..., but it triggers the error.
^
compilation aborted for testshape.f90 (code 1)

If we remove -check shape or replace it with -warn shape, then everything works.

Did I misunderstand array indexing or miscalculate something in the code? Thank you for your attention.

1 Like

No, your program is correct as far as I can see. The compiler is simply in error here, which you can see by a rather careful reading of the error message: it compares the extent of the first dimension of the left-hand side with the second dimension on the right-hand side.
I changed the first dimension to 2 and the error disappeared. It reappeared with a first dimension set to 3.

2 Likes

Thank you @Arjen for the response. I will report it to Intel.

Hi, @Beliavsky, thank you for the editing.

I must have overlooked something … This is what happens on my computer:

ifort -check:shape testshape.f90
ifort: command line warning #10158: ignoring option '-check'; argument must be separate

Thanks.

@zaikunzhang , I have reverted the edits, sorry. The syntax for the option is different on Windows and Linux:

To enable array shape checking, compile with -check shape (Linux* and macOS*) or /check:shape (Windows*).

2 Likes

I see. Windows is always difficult. Thank you!

1 Like