[committed] Fortran: Fix 'fn spec' for deferred character length (was: Re: [r12-4457 Regression] FAIL: gfortran.dg/deferred_type_param_6.f90 -Os execution test on Linux/x86_64)
Commit Message
On 16.10.21 20:54, Jan Hubicka wrote:
> I wrote:
>> Fortran has for a long time 'character(len=5), allocatable" or
>> "character(len=*)". In the first case, the "5" can be ignored as both
>> caller and callee know the length. In the second case, the length is
>> determined by the argument, but it cannot be changed.
>>
>> Since a not-that-short while, 'len=:' together with allocatable/pointer
>> is supported.
>>
>> In the latter case, the value can be change when the array
>> association/allocation is changed.
>> ...
>> + if (!sym->ts.u.cl->length
>> + && ((sym->attr.allocatable && sym->attr.target)
>> + || sym->attr.pointer))
>> + spec[spec_len++] = '.';
>> + if (!sym->ts.u.cl->length && sym->attr.allocatable)
>> + spec[spec_len++] = 'w';
>> + else
>> + spec[spec_len++] = 'R';
> Also escaping is quite important bit of information so it would be
> good to figure out if it really can escape rather than playing safe.
The pointer to the string length variable itself does not escape,
only its integer string value:
subroutine foo(x)
character(len=:), pointer :: x
character(len=:), pointer :: y
y => x
has in the dump:
.y = *_x;
y = (character(kind=1)[1:.y] *) *x;
Thus, 'w' can always be used.
Committed as obvious as r12-4511-gff0eec94e87dfb7dc387f120ca5ade2707aecf50
Tobias
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
commit ff0eec94e87dfb7dc387f120ca5ade2707aecf50
Author: Tobias Burnus <tobias@codesourcery.com>
Date: Tue Oct 19 16:38:56 2021 +0200
Fortran: Fix 'fn spec' for deferred character length
Shows now up with gfortran.dg/deferred_type_param_6.f90 due to more ME
optimizations, causing fails without this commit.
gcc/fortran/ChangeLog:
* trans-types.c (create_fn_spec): For allocatable/pointer
character(len=:), use 'w' not 'R' as fn spec for the length dummy
argument.
---
gcc/fortran/trans-types.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
@@ -3014,7 +3014,11 @@ create_fn_spec (gfc_symbol *sym, tree fntype)
}
if (sym->ts.type == BT_CHARACTER)
{
- spec[spec_len++] = 'R';
+ if (!sym->ts.u.cl->length
+ && (sym->attr.allocatable || sym->attr.pointer))
+ spec[spec_len++] = 'w';
+ else
+ spec[spec_len++] = 'R';
spec[spec_len++] = ' ';
}
}