Le 01/03/2014 16:58, Janus Weil a écrit :
>>> Index: gcc/fortran/trans-stmt.c
>>> ===================================================================
>>> --- gcc/fortran/trans-stmt.c  (revision 207896)
>>> +++ gcc/fortran/trans-stmt.c  (working copy)
>>> @@ -5028,6 +5028,11 @@ gfc_trans_allocate (gfc_code * code)
>>>             if (tmp && TREE_CODE (tmp) == VAR_DECL)
>>>               gfc_add_modify (&se.pre, tmp, fold_convert (TREE_TYPE (tmp),
>>>                               memsz));
>>> +           else if (al->expr->ts.type == BT_CHARACTER
>>> +                    && al->expr->ts.deferred && se.string_length)
>>> +             gfc_add_modify (&se.pre, se.string_length,
>>> +                             fold_convert (TREE_TYPE (se.string_length),
>>> +                             memsz));
>>>
>> and here.  There may be other places that I have missed.
> 
> Actually I don't see a problem here. Also no further modifications
> were necessary to get a KIND=4 example to work.
> 
Mmmh, yes indeed.  I assumed memsz was the memory size, which it isn't
until a few lines down.  Thanks for checking.

> 
>>>             /* Convert to size in bytes, using the character KIND.  */
>>>             if (unlimited_char)
>>
>> As the patch seems to provide a wanted feature, and as the new code
>> seems to be properly guarded, I'm not against it after the above has
>> been checked and fixed if necessary.
> 
> Attached is a new version of the patch which fixes the above-mentioned
> problems and should make the non-default-kind cases work. I have added
> a KIND=4 version of the original test case, which seems to work
> properly.
> 
> The patch was regtested on x86_64-unknown-linux-gnu. Ok for trunk?
> 
I'm asking for one more minor change, namely:

> @@ -12364,6 +12356,25 @@ resolve_fl_derived0 (gfc_symbol *sym)
>         return false;
>       }
>  
> +      /* Add the hidden deferred length field.  */
> +      if (c->ts.type == BT_CHARACTER && c->ts.deferred && !c->attr.function
> +       && !sym->attr.is_class)
> +     {
> +       char name[GFC_MAX_SYMBOL_LEN+1];
> +       gfc_component *strlen;
> +       sprintf (name, "_%s", c->name);

It's not more costly to have a more explicit name like "_%s_length" or
something, and I prefer having the latter in complicated dumps or in the
debugger.
OK with that change, with the associated buffer size update.  Also Steve
noted that the buffer size should take the terminating null character
into account.

Thanks for the patch.
Mikael

Reply via email to