Patchwork [Fortran,(RFC)] PR49110/51055 Assignment to alloc. deferred-length character vars

login
register
mail settings
Submitter Tobias Burnus
Date Dec. 18, 2012, 7:45 p.m.
Message ID <50D0C7ED.7020809@net-b.de>
Download mbox | patch
Permalink /patch/207189/
State New
Headers show

Comments

Tobias Burnus - Dec. 18, 2012, 7:45 p.m.
Jakub Jelinek wrote:
> On Tue, Dec 18, 2012 at 04:40:10PM +0100, Tobias Burnus wrote:
>> Looks mostly okay, however, I fear that for
>>
>> subroutine foo()
>> character(len=:), allocatable :: str
>> allocate(str, stat=istat)
>> end subroutine foo
>>
>> compiled with "-fno-automatic", gfortran will still generate the
>> non-GFC_PREFIX-mangled string.
> That doesn't compile:
> Error: Allocate-object at (1) with a deferred type parameter requires either a type-spec or SOURCE tag or a MOLD tag

Sorry for the bad example. I added the allocate just to mark the 
variable as used (otherwise no decl is generated); but my cut-down 
example was wrong. Try:

subroutine foo()
   character(len=:), allocatable :: str
   print *, allocated(str)
end subroutine foo


Or one of the examples from PR55733. The example above gives currently 
(w/o your patch):

   static character(kind=1)[1:.str] * str = 0B;
   integer(kind=4) .str;


> Where would be TREE_STATIC set on the length variable with -fno-automatic,
> and on which testcase?

As written, TREE_STATIC is currently not set (which is a bug, cf. 
PR55733); I think one needs a patch like:



Tobias
Jakub Jelinek - Dec. 18, 2012, 7:49 p.m.
On Tue, Dec 18, 2012 at 08:45:49PM +0100, Tobias Burnus wrote:
> Or one of the examples from PR55733. The example above gives
> currently (w/o your patch):
> 
>   static character(kind=1)[1:.str] * str = 0B;
>   integer(kind=4) .str;

Yeah, that is not a problem for ABI.

> >Where would be TREE_STATIC set on the length variable with -fno-automatic,
> >and on which testcase?
> 
> As written, TREE_STATIC is currently not set (which is a bug, cf.
> PR55733); I think one needs a patch like:
> 
> --- a/gcc/fortran/trans-decl.c
> +++ b/gcc/fortran/trans-decl.c
> @@ -1107,3 +1107,4 @@ gfc_create_string_length (gfc_symbol * sym)
> 
> -      if (sym->attr.save || sym->ns->proc_name->attr.flavor == FL_MODULE)
> +      if (sym->attr.save || sym->ns->proc_name->attr.flavor == FL_MODULE
> +         || gfc_option.flag_max_stack_var_size == 0)
>         TREE_STATIC (length) = 1;

If that is changed, surely the name must be mangled too.
Perhaps best to set a bool variable to the condition and use it in both
places.
  bool static_length = sym->attr.save
		      || sym->ns->proc_name->attr.flavor == FL_MODULE
		      || gfc_option.flag_max_stack_var_size == 0;
  if (static_length)
    {
      name mangling;
    }
  else ...

...
  if (static_length)
    TREE_STATIC (length) = 1;

	Jakub

Patch

--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -1107,3 +1107,4 @@  gfc_create_string_length (gfc_symbol * sym)

-      if (sym->attr.save || sym->ns->proc_name->attr.flavor == FL_MODULE)
+      if (sym->attr.save || sym->ns->proc_name->attr.flavor == FL_MODULE
+         || gfc_option.flag_max_stack_var_size == 0)
         TREE_STATIC (length) = 1;