[PATCH] fortran: Make IS_CONTIGUOUS true for assumed-rank scalars [PR126895]
Mikael Morin <[email protected]>
| Newsgroups | gmane.comp.gcc.patches,gmane.comp.gcc.fortran |
|---|---|
| Message-ID | <[email protected]> |
Hello, I plan to push this later today or tomorrow. Fortran-testing on aarch64-unknown-linux-gnu is in progress. Mikael
pr126895_v01-03.patch
(text/x-patch, 2.6 KB)
From 00b8c3951e824ff89c735b744048e168a97dadfe Mon Sep 17 00:00:00 2001 From: Mikael Morin <[email protected]> Date: Sat, 15 Aug 2026 21:54:06 +0200 Subject: [PATCH] fortran: Make IS_CONTIGUOUS true for assumed-rank scalars [PR126895] If the argument to IS_CONTIGUOUS is an assumed-rank variable, add a condition making the intrinsic return true if the variable rank is zero at execution time. With the testcase, the function returned false despite the rank, because the check of the span against the element size, that compared unequal, was not guarded by a rank check. PR fortran/126895 gcc/fortran/ChangeLog: * trans-intrinsic.cc (gfc_conv_is_contiguous_expr): If the argument to IS_CONTIGUOUS is an assumed-rank variable, add a conditional making the value true if the runtime rank is zero. gcc/testsuite/ChangeLog: * gfortran.dg/is_contiguous_7.f90: New test. --- gcc/fortran/trans-intrinsic.cc | 9 +++++++ gcc/testsuite/gfortran.dg/is_contiguous_7.f90 | 26 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/is_contiguous_7.f90 diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc index 69a6034b3d3..31d81e517e7 100644 --- a/gcc/fortran/trans-intrinsic.cc +++ b/gcc/fortran/trans-intrinsic.cc @@ -2400,6 +2400,15 @@ gfc_conv_is_contiguous_expr (gfc_se *se, gfc_expr *arg) convert (boolean_type_node, se->expr)); } + if (as && as->type == AS_ASSUMED_RANK) + { + tree rank = gfc_conv_descriptor_rank_get (desc); + tree scalar = fold_build2_loc (input_location, EQ_EXPR, boolean_type_node, + rank, gfc_rank_cst[0]); + se->expr = fold_build2_loc (input_location, TRUTH_ORIF_EXPR, + TREE_TYPE (se->expr), scalar, se->expr); + } + gfc_free_ss_chain (ss); } diff --git a/gcc/testsuite/gfortran.dg/is_contiguous_7.f90 b/gcc/testsuite/gfortran.dg/is_contiguous_7.f90 new file mode 100644 index 00000000000..806f1f31874 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/is_contiguous_7.f90 @@ -0,0 +1,26 @@ +! { dg-do run } +! +! PR fortran/126895 +! The IS_CONTIGUOUS intrinsic used to erroneously return FALSE for pointer +! assumed-rank dummies associated with a scalar value. + +program prog + implicit none + type :: t + integer :: c1 + end type + type, extends(t) :: u + integer :: c2 + end type + type(t), target :: x + type(u), target :: y + call s1(x, 1) + call s1(y, 2) +contains + subroutine s1(a, e) + class(t), pointer, intent(in) :: a(..) + integer, value :: e + !print *, is_contiguous(a) + if (.not. is_contiguous(a)) error stop e + end subroutine +end program -- 2.53.0