Fortran: Fix reallocation on assignment for kind=4 strings [PR107508]
authorTobias Burnus <tobias@codesourcery.com>
Mon, 7 Nov 2022 10:32:33 +0000 (11:32 +0100)
committerTobias Burnus <tobias@codesourcery.com>
Mon, 7 Nov 2022 10:32:33 +0000 (11:32 +0100)
commit071d00e0faabbd45449d2e83f207fca0f8e8ef68
tree84c47e3261635ef97b6a310c0cd21638bf2f9343
parent21cd625eb8f055a72ee056be32a958b786843e80
Fortran: Fix reallocation on assignment for kind=4 strings [PR107508]

The check whether reallocation on assignment was required did not handle
kind=4 characters correctly such that there was always a reallocation,
implying issues with pointer addresses and lower bounds.  Additionally,
with all deferred strings, the old memory was not freed on reallocation.
And, finally, inside the block which was only executed if string lengths
or bounds or dynamic types changed, was a subcheck of the same, which
was effectively a no op but still confusing and at least added with -O0
extra instructions to the binary.

PR fortran/107508

gcc/fortran/ChangeLog:

* trans-array.cc (gfc_alloc_allocatable_for_assignment): Fix
string-length check, plug memory leak, and avoid generation of
effectively no-op code.
* trans-expr.cc (alloc_scalar_allocatable_for_assignment): Extend
comment; minor cleanup.

gcc/testsuite/ChangeLog:

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