Committed as obvious in r254624. I will apply to 6- and 7-branches over the weekend. Although not a regression, the fix prevents an ICE in a particularly robust way.
Cheers Paul 2017-11-10 Paul Thomas <pa...@gcc.gnu.org> PR fortran/82934 * trans-stmt.c (gfc_trans_allocate): Remove the gcc_assert on null string length for assumed length typespec and set expr3_esize to NULL_TREE; 2017-11-10 Paul Thomas <pa...@gcc.gnu.org> PR fortran/82934 * gfortran.dg/allocate_assumed_charlen_1.f90: New test.
Index: gcc/fortran/trans-stmt.c =================================================================== *** gcc/fortran/trans-stmt.c (revision 254604) --- gcc/fortran/trans-stmt.c (working copy) *************** gfc_trans_allocate (gfc_code * code) *** 5913,5922 **** if (code->ext.alloc.ts.type != BT_CHARACTER) expr3_esize = TYPE_SIZE_UNIT ( gfc_typenode_for_spec (&code->ext.alloc.ts)); ! else { gfc_expr *sz; - gcc_assert (code->ext.alloc.ts.u.cl->length != NULL); sz = gfc_copy_expr (code->ext.alloc.ts.u.cl->length); gfc_init_se (&se_sz, NULL); gfc_conv_expr (&se_sz, sz); --- 5913,5921 ---- if (code->ext.alloc.ts.type != BT_CHARACTER) expr3_esize = TYPE_SIZE_UNIT ( gfc_typenode_for_spec (&code->ext.alloc.ts)); ! else if (code->ext.alloc.ts.u.cl->length != NULL) { gfc_expr *sz; sz = gfc_copy_expr (code->ext.alloc.ts.u.cl->length); gfc_init_se (&se_sz, NULL); gfc_conv_expr (&se_sz, sz); *************** gfc_trans_allocate (gfc_code * code) *** 5930,5935 **** --- 5929,5936 ---- tmp, se_sz.expr); expr3_esize = gfc_evaluate_now (expr3_esize, &block); } + else + expr3_esize = NULL_TREE; } /* The routine gfc_trans_assignment () already implements all Index: gcc/testsuite/gfortran.dg/allocate_assumed_charlen_1.f90 =================================================================== *** gcc/testsuite/gfortran.dg/allocate_assumed_charlen_1.f90 (nonexistent) --- gcc/testsuite/gfortran.dg/allocate_assumed_charlen_1.f90 (working copy) *************** *** 0 **** --- 1,28 ---- + ! { dg-do run } + ! + ! PR82934: Segfault on compilation in trans-stmt.c:5919(8.0.0). + ! The original report only had one item in the allocate list. This + ! has been doubled up to verify that the correct string length is + ! is used in the allocation. + ! + ! Contributed by FortranFan on clf. + ! + character(len=42), allocatable :: foo + character(len=22), allocatable :: foofoo + + call alloc( foo , foofoo) + + if (len(foo) .ne. 42) call abort + if (len(foofoo) .ne. 22) call abort + + contains + + subroutine alloc( bar, barbar ) + + character(len=*), allocatable :: bar, barbar + + allocate( character(len=*) :: bar , barbar) ! <= Here! + + end subroutine + + end