diff mbox

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

Message ID 50D0C7ED.7020809@net-b.de
State New
Headers show

Commit Message

Tobias Burnus Dec. 18, 2012, 7:45 p.m. UTC
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

Comments

Jakub Jelinek Dec. 18, 2012, 7:49 p.m. UTC | #1
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
diff mbox

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;