https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112371
Bug ID: 112371 Summary: Wrong upper bound for the result of reduction intrinsics if the array is empty Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: mikael at gcc dot gnu.org Target Milestone: --- In the following example, I expect the ubound to be (/ 3, 0, 7 /), but the printed values are (/ 0, 0, 7 /). program p implicit none call check_iparity call check_sum call check_minloc contains subroutine check_iparity integer :: a(9,3,0,7) integer :: i integer, allocatable :: r(:,:,:) i = 1 a = reshape((/ integer:: /), shape(a)) r = iparity(a, dim=i) print *, shape(r) print *, ubound(r) ! if (any(shape(r) /= (/ 3, 0, 7 /))) stop 11 ! if (any(ubound(r) /= (/ 3, 0, 7 /))) stop 13 end subroutine subroutine check_sum integer :: a(9,3,0,7) integer :: i integer, allocatable :: r(:,:,:) i = 1 a = reshape((/ integer:: /), shape(a)) r = sum(a, dim=i) print *, shape(r) print *, ubound(r) ! if (any(shape(r) /= (/ 3, 0, 7 /))) stop 21 ! if (any(ubound(r) /= (/ 3, 0, 7 /))) stop 23 end subroutine subroutine check_minloc integer :: a(9,3,0,7) integer :: i integer, allocatable :: r(:,:,:) i = 1 a = reshape((/ integer:: /), shape(a)) r = minloc(a, dim=i) print *, shape(r) print *, ubound(r) ! if (any(shape(r) /= (/ 3, 0, 7 /))) stop 31 ! if (any(ubound(r) /= (/ 3, 0, 7 /))) stop 33 end subroutine end program