]> git.ipfire.org Git - thirdparty/gcc.git/commit
fortran: Trigger reference saving on pointer dereference [PR121185]
authorMikael Morin <mikael@gcc.gnu.org>
Sun, 27 Jul 2025 15:11:50 +0000 (17:11 +0200)
committerMikael Morin <mikael@gcc.gnu.org>
Sun, 27 Jul 2025 15:25:51 +0000 (17:25 +0200)
commit1800ac20f66812c72b144848f7ec8e66156f06f8
tree8ef9e6083361ab7988d53423a9e0cadf0bbde393
parent5f9f20df98b1fe8dd8b179b157d268470bde70f4
fortran: Trigger reference saving on pointer dereference [PR121185]

This is a follow-up to revision:
r16-2371-g8f41c87654fd819e48c9f6f1ac3d87e35794d310
fortran: Factor array descriptor references

That revision introduced new variables to limit repeated subexpressions
in array descriptor references.  The change added a walk along the
reference from child to parent, that selected subreferences worth
saving and applied the saving if the reference proved non-trivial
enough.  Trivialness was defined in a comment as: only made of a DECL
and NOPs and COMPONENTs.  But the case of a pointer derefence didn't
trigger the saving, so the code was also considering a dereference as if
it was trivial.

This change triggers the reference saving on pointer dereferences,
making the trivialness as defined by the code aligned with the comment.

This change is not strictly speaking a bug fix, but PR #121185 exhibited
wrong code examples where the lack of a variable hiding the polymorphic
leading part of a non-polymorphic array reference was causing the latter
to be evaluated in a polymorphic way.

PR fortran/121185

gcc/fortran/ChangeLog:

* trans-array.cc (set_factored_descriptor_value): Also trigger
the saving of the previously selected reference on encountering
an INDIRECT_REF.  Extract the saving code...
(save_ref): ... here as a new function.

gcc/testsuite/ChangeLog:

* gfortran.dg/assign_14.f90: New test.
gcc/fortran/trans-array.cc
gcc/testsuite/gfortran.dg/assign_14.f90 [new file with mode: 0644]