]> git.ipfire.org Git - thirdparty/gcc.git/commit
fortran: Mention user variable in SELECT TYPE temporary variable names
authorMikael Morin <morin-mikael@orange.fr>
Fri, 20 Jun 2025 10:08:02 +0000 (12:08 +0200)
committerMikael Morin <mikael@gcc.gnu.org>
Tue, 24 Jun 2025 09:10:00 +0000 (11:10 +0200)
commit3f88230da6a5fbdee1458ea6abc61ecb4b926cd0
treefbf0ba9ec1783724a3366d37173d93602ff4e43c
parentc06979ff95748559da0c2d3aa4eda9d5999eaaf6
fortran: Mention user variable in SELECT TYPE temporary variable names

The temporary variables that are generated to implement SELECT TYPE
and TYPE IS statements have (before this change) a name depending only
on the type.  This can produce confusing dumps with code having multiple
SELECT TYPE statements, as it isn't obvious which SELECT TYPE construct
the variable relates to.  This is especially the case with nested SELECT
TYPE statements and with SELECT TYPE variables having identical types
(and thus identical names).

This change adds one additional user-provided discriminating string in
the variable names, using the value from the SELECT TYPE variable name
or last component reference name.  The additional string may be
truncated to fit in the temporary buffer.  This requires all buffers to
have matching sizes to get the same resulting name everywhere.

gcc/fortran/ChangeLog:

* misc.cc (gfc_var_name_for_select_type_temp): New function.
* gfortran.h (gfc_var_name_for_select_type_temp): Declare it.
* resolve.cc (resolve_select_type): Pick a discriminating name
from the SELECT TYPE variable reference and use it in the name
of the temporary variable that is generated.  Truncate name to
the buffer size.
* match.cc (select_type_set_tmp): Likewise.  Pass the
discriminating name...
(select_intrinsic_set_tmp): ... to this function.  Use the
discriminating name likewise.  Augment the buffer size to match
that of select_type_set_tmp and resolve_select_type.

gcc/testsuite/ChangeLog:

* gfortran.dg/select_type_51.f90: New test.
gcc/fortran/gfortran.h
gcc/fortran/match.cc
gcc/fortran/misc.cc
gcc/fortran/resolve.cc
gcc/testsuite/gfortran.dg/select_type_51.f90 [new file with mode: 0644]