We have installed the latest ifort version (2021.2.0) hoping to solve our problems with the -check shape option. But the simple program below still gets an error message with -check shape:
INTEGER, DIMENSION(2) :: array1dim
INTEGER, DIMENSION(2) :: array1dimbis
INTEGER, DIMENSION(3,2) :: array2dim
INTEGER, DIMENSION(4,3,2) :: array3dim
!Fails with -check shape
!error #5581: Shape mismatch: The extent of dimension 1 of array ARRAY1DIM is 2 and the corresponding extent of array ARRAY3DIM is 3
!array1dim(:) = array1dim(:) + SUM(array3dim(1,:,:),1)
array1dim(:) = array1dim(:) + SUM(array3dim(1,:,:),1)
write(*,*) 'array1dim(:) =',array1dim
!OK with -check shape. Same result as above without -check shape
array2dim(:,:) = array3dim(1,:,:)
array1dimbis(:) = array1dimbis(:) + SUM(array2dim(:,:),1)
write(*,*) 'array1dimbis(:) =',array1dimbis
!array1dim(:) = 363 663
!array1dimbis(:) = 363 663
Let me know what you think: is there really a problem with the compiler, or are we doing something wrong?
There really is a problem with the compiler.
The shape of array3dim(1,:,:) is [3,2]. The shape of SUM(array3dim(1,:,:),1) is . The compiler should not even be testing the shape of array3dim here.
Thanks for the nice reproducer. I filed a bug on your behalf, CMPLRIL0-33973. This one won't be fixed in the compiler that is planned to be released in the next couple of weeks.
The fix is in review. The fix missed the code cutoff for 2021.4.0, but look for it in 2022.1 later this year. I'll post it here when the fix is available to you.
The compiler engineer points out this workaround. Replace "dim=1" with a variable.
var_dim = 1 array1dim(:) = array1dim(:) + SUM(array3dim(1,:,:),dim=var_dim)
This issue you reported when using -check shape is fixed in ifort version 2021.6.0. This compiler version is part of the oneAPI HPC Toolkit 2022.2 that was recently released.