[gcc(refs/users/mikael/heads/refactor_descriptor_v206.01)] fortran: array descriptor: Don't set the span in the scalar case [PR122521]
Mikael Morin via Gcc-cvs <[email protected]>
| Newsgroups | gmane.comp.gcc.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://gcc.gnu.org/g:206c394124d5dc2ea4b9c03badd73034c957b0f7 commit 206c394124d5dc2ea4b9c03badd73034c957b0f7 Author: Mikael Morin <[email protected]> Date: Mon Aug 10 21:40:12 2026 +0200 fortran: array descriptor: Don't set the span in the scalar case [PR122521] The span in an array descriptor is a multiplier of the stride representing the address difference between two consecutive array elements. For scalar descriptors, there is a single element, so it can't be used in any useful way. This patch removes the initialization of the span of descriptors in the scalar case. One additional tweak is required to avoid regressing. In the library implementation of the ASSOCIATED intrinsic, the two descriptors are checked to have the same span, assuming the span to be always set. Make that check conditional on the rank being non-zero. PR fortran/122521 gcc/fortran/ChangeLog: * trans-descriptor.cc (gfc_set_descriptor_from_scalar): Remove descriptor span initialization. libgfortran/ChangeLog: * intrinsics/associated.c (associated): Only compare spans if the rank is non-zero. gcc/testsuite/ChangeLog: * gfortran.dg/coarray_collectives_18.f90: Update pattern count. Diff: --- gcc/fortran/trans-descriptor.cc | 2 -- gcc/testsuite/gfortran.dg/coarray_collectives_18.f90 | 2 +- libgfortran/intrinsics/associated.c | 5 +++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc index 6ec9593c3b7b..a7739355d4cb 100644 --- a/gcc/fortran/trans-descriptor.cc +++ b/gcc/fortran/trans-descriptor.cc @@ -880,8 +880,6 @@ gfc_set_descriptor_from_scalar (stmtblock_t *block, tree descr, tree scalar) gfc_conv_descriptor_dtype_set (block, descr, gfc_get_dtype_rank_type (0, etype)); gfc_conv_descriptor_data_set (block, descr, scalar); - gfc_conv_descriptor_span_set (block, descr, - gfc_conv_descriptor_elem_len_get (descr)); } diff --git a/gcc/testsuite/gfortran.dg/coarray_collectives_18.f90 b/gcc/testsuite/gfortran.dg/coarray_collectives_18.f90 index c83899de0e5b..5636a89e94a9 100644 --- a/gcc/testsuite/gfortran.dg/coarray_collectives_18.f90 +++ b/gcc/testsuite/gfortran.dg/coarray_collectives_18.f90 @@ -33,5 +33,5 @@ end program ! This lead to access to non exsitant memory in opencoarrays. ! In single image mode just checking for reduced number of ! descriptors is possible, i.e., execute always works. -! { dg-final { scan-tree-dump-times "desc\\.\[0-9\]+" 12 "original" } } +! { dg-final { scan-tree-dump-times "desc\\.\[0-9\]+" 8 "original" } } diff --git a/libgfortran/intrinsics/associated.c b/libgfortran/intrinsics/associated.c index fecc1b3a2832..b597b862d031 100644 --- a/libgfortran/intrinsics/associated.c +++ b/libgfortran/intrinsics/associated.c @@ -37,13 +37,14 @@ associated (const gfc_array_void *pointer, const gfc_array_void *target) return 0; if (GFC_DESCRIPTOR_DATA (pointer) != GFC_DESCRIPTOR_DATA (target)) return 0; - if (GFC_DESCRIPTOR_SPAN (pointer) != GFC_DESCRIPTOR_SPAN (target)) - return 0; if (GFC_DESCRIPTOR_DTYPE (pointer).type != GFC_DESCRIPTOR_DTYPE (target).type) return 0; rank = GFC_DESCRIPTOR_RANK (pointer); if (rank != GFC_DESCRIPTOR_RANK (target)) return 0; + if (rank != 0 + && GFC_DESCRIPTOR_SPAN (pointer) != GFC_DESCRIPTOR_SPAN (target)) + return 0; for (n = 0; n < rank; n++) { long extent;