]> git.ipfire.org Git - thirdparty/gcc.git/commit
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, 10 Apr 2022 16:40:10 +0000 (18:40 +0200)
commit3b0f715744d7919ee729d370155a68d5fa97cba9
tree538f9922fa8add0644653cb8ac6b0fbbe38c78ad
parenta9c54c5ec762672d600d312336217ccaa7ffd8e4
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.c (resolve_assoc_var): Also create a new character
length for non-dummy associate targets.
* trans-stmt.c (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.

(cherry picked from commit 57da34939703a6e6d3267a0d25d1fb9369d3ac0e)
gcc/fortran/resolve.c
gcc/fortran/trans-stmt.c
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]