fortran: Unshare associate var charlen [PR104228]
authorMikael Morin <mikael@gcc.gnu.org>
Fri, 28 Jan 2022 21:00:57 +0000 (22:00 +0100)
committerMikael Morin <mikael@gcc.gnu.org>
Sun, 13 Feb 2022 15:46:46 +0000 (16:46 +0100)
commit57da34939703a6e6d3267a0d25d1fb9369d3ac0e
tree980531df7698c39dd08c736aa5f60f7bc7f4c9b4
parent7e204bd2f189850cb940677c99d8d93eb7dd40cd
fortran: Unshare associate var charlen [PR104228]

PR104228 showed that character lengths were shared between associate
variable and associate targets.  This is problematic when the associate
target is itself a variable and gets a variable to hold the length, as
the length variable is added (and all the variables following it in the chain)
to both the associate variable scope and the target variable scope.
This caused an ICE when compiling with -O0 -fsanitize=address.

This change forces the creation of a separate character length for the
associate variable.  It also forces the initialization of the character
length variable to avoid regressing associate_32 and associate_47 tests.

PR fortran/104228

gcc/fortran/ChangeLog:

* resolve.cc (resolve_assoc_var): Also create a new character
length for non-dummy associate targets.
* trans-stmt.cc (trans_associate_var): Initialize character length
even if no temporary is used for the associate variable.

gcc/testsuite/ChangeLog:

* gfortran.dg/asan/associate_58.f90: New test.
* gfortran.dg/asan/associate_59.f90: New test.
gcc/fortran/resolve.cc
gcc/fortran/trans-stmt.cc
gcc/testsuite/gfortran.dg/asan/associate_58.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/asan/associate_59.f90 [new file with mode: 0644]