From patchwork Tue Dec 18 19:45:49 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [Fortran, (RFC)] PR49110/51055 Assignment to alloc. deferred-length character vars From: Tobias Burnus X-Patchwork-Id: 207189 Message-Id: <50D0C7ED.7020809@net-b.de> To: Jakub Jelinek Cc: Janus Weil , David Edelsohn , Fortran List , Paul Richard Thomas , GCC Patches Date: Tue, 18 Dec 2012 20:45:49 +0100 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 --- 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;