From: Mikael Morin <[email protected]>

This used to be part 3 of the array descriptor series, and I've been wondering
whether I should include this part or drop it.  Indeed, the first patch causes
some verbosity in the tree dumps that some may find excessive.  Worse, broader
testing revealed errors with objc and modula2 caused by the second patch, which
disqualifies the series anyway.  I'm posting these patches nevertheless for
archiving purpose.

--

The previous part in the series introduced a separation between read access and
write access to array descriptor fields, but there is nothing that actually
prevents writing to the reference returned by a getter, supposed to be
read-only.  This is not only a theoretical concern; I fixed a few cases in
August 2025 [1], and two more recently [2].

This part remedies to that problem.  It's done by wrapping the reference
returned by getters in a NON_LVALUE (patch 1) and rejecting NON_LVALUE as
assignment left hand side at gimplification time (patch 2).  This causes some
churn in the testsuite where we try to match the code generated involving
getters in the dump files.  I posted a patch to avoid the churn in cases where
the getters were used as operands of an outer operation [3], but it was
suggested in review to explore a different direction, which didn't work so well
and I finally dropped it.

[1] fortran: Use existing setters and getters to access array descriptors
  https://gcc.gnu.org/pipermail/gcc-patches/2025-August/691488.html
  https://gcc.gnu.org/pipermail/fortran/2025-August/062659.html

[2] fortran: Use the setter to update the descriptor data field
  https://gcc.gnu.org/pipermail/gcc-patches/2026-July/724651.html
  https://gcc.gnu.org/pipermail/fortran/2026-July/064350.html

[3] match: Unwrap non-lvalue as unary or binary operand
  https://gcc.gnu.org/pipermail/gcc-patches/2025-June/687228.html

Previous parts in the series:

part 2 (pushed): Add getters and setters
  https://gcc.gnu.org/pipermail/gcc-patches/2026-July/723604.html
  https://gcc.gnu.org/pipermail/fortran/2026-July/064287.html

part 1 (pushed): Move existing functions to a separate file
  https://gcc.gnu.org/pipermail/gcc-patches/2026-June/721900.html
  https://gcc.gnu.org/pipermail/fortran/2026-June/064198.html

Mikael Morin (2):
  fortran: array descriptor: Wrap getter results in a non_lvalue
    [PR122521]
  gimplify: reject non-lvalue as assignment lhs [PR122521]

 gcc/fold-const.cc                             |  2 +-
 gcc/fold-const.h                              |  1 +
 gcc/fortran/trans-descriptor.cc               | 20 +++++------
 gcc/gimplify.cc                               | 35 +++++++++++++++++++
 gcc/testsuite/gfortran.dg/PR93963.f90         |  2 +-
 .../gfortran.dg/array_reference_3.f90         | 10 +++---
 .../gfortran.dg/bind-c-contiguous-2.f90       | 12 +++----
 .../gfortran.dg/bind_c_array_params_2.f90     |  4 +--
 .../gfortran.dg/coarray_lib_this_image_1.f90  |  2 +-
 .../gfortran.dg/coarray_lib_this_image_2.f90  |  2 +-
 gcc/testsuite/gfortran.dg/coarray_lock_7.f90  | 12 +++----
 gcc/testsuite/gfortran.dg/contiguous_3.f90    |  4 +--
 gcc/testsuite/gfortran.dg/gomp/depend-4.f90   | 24 ++++++-------
 gcc/testsuite/gfortran.dg/gomp/depend-5.f90   | 12 +++----
 gcc/testsuite/gfortran.dg/gomp/depend-6.f90   | 25 ++++++-------
 .../gfortran.dg/intrinsic_size_3.f90          |  2 +-
 .../libgomp.fortran/allocators-1.f90          |  4 +--
 17 files changed, 105 insertions(+), 68 deletions(-)

-- 
2.53.0

Reply via email to