https://gcc.gnu.org/g:0bae2f4512a768ddc0fbcb25bf74dc40c96b6e91
commit r17-6564-g0bae2f4512a768ddc0fbcb25bf74dc40c96b6e91 Author: Jerry DeLisle <[email protected]> Date: Wed Nov 18 14:51:07 2026 -0800 fortran: IS_CONTIGUOUS true for a section with a vector subscript IS_CONTIGUOUS returned .true. for an array section with a vector subscript, such as A([1,3]), because the run-time test inspected the contiguous temporary that is built for such a section. F2023 8.5.7 does not make a section with a vector subscript contiguous, so simplify the result to .false. Assisted-by: Claude Opus 5.5 gcc/fortran/ChangeLog: * simplify.cc (gfc_simplify_is_contiguous): Return .false. for an array section with a vector subscript. gcc/testsuite/ChangeLog: * gfortran.dg/is_contiguous_8.f90: New test. Diff: --- gcc/fortran/simplify.cc | 4 +++- gcc/testsuite/gfortran.dg/is_contiguous_8.f90 | 28 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/gcc/fortran/simplify.cc b/gcc/fortran/simplify.cc index f334dafed1c7..2cec0011608f 100644 --- a/gcc/fortran/simplify.cc +++ b/gcc/fortran/simplify.cc @@ -7412,7 +7412,9 @@ gfc_simplify_is_contiguous (gfc_expr *array) if (gfc_is_simply_contiguous (array, false, true)) return gfc_get_logical_expr (gfc_default_logical_kind, &array->where, 1); - if (gfc_is_not_contiguous (array)) + /* F2023 8.5.7 does not make a section with a vector subscript + contiguous, so say it is not. */ + if (gfc_is_not_contiguous (array) || gfc_has_vector_subscript (array)) return gfc_get_logical_expr (gfc_default_logical_kind, &array->where, 0); return NULL; diff --git a/gcc/testsuite/gfortran.dg/is_contiguous_8.f90 b/gcc/testsuite/gfortran.dg/is_contiguous_8.f90 new file mode 100644 index 000000000000..8e224d4338d4 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/is_contiguous_8.f90 @@ -0,0 +1,28 @@ +! { dg-do run } + +program p + implicit none + integer :: a(10), b(10,10), k(2) = [1,3] + real, allocatable :: r(:,:) + character(len=4), target :: c(10,10) + allocate (r(4,4)) + if (is_contiguous (a([1,3]))) stop 1 + if (is_contiguous (a(k))) stop 2 + if (is_contiguous (b(:,[1,3]))) stop 3 + if (is_contiguous (r(:,k))) stop 4 + call s (b) + call t (c) +contains + subroutine s (x) + integer :: x(:,:) + if (is_contiguous (x(:,[1,3]))) stop 5 + if (is_contiguous (x([1,3],1))) stop 6 + if (is_contiguous (x([1,2],:))) stop 7 + end subroutine + subroutine t (y) + character(len=4), target :: y(:,:) + if (is_contiguous (y(:,[1,3]))) stop 8 + if (is_contiguous (y([1,2],:)(1:4))) stop 9 + if (is_contiguous (y(:,[1,2])(1:2))) stop 10 + end subroutine +end program
