From 8cd119d857b727ce0ee7b3c7aead38d8fdcc1a7e Mon Sep 17 00:00:00 2001 From: Paul Thomas Date: Fri, 10 Nov 2017 12:24:24 +0000 Subject: [PATCH] re PR fortran/82934 (Segfault on assumed character length in allocate) 2017-11-10 Paul Thomas 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 PR fortran/82934 * gfortran.dg/allocate_assumed_charlen_1.f90: New test. From-SVN: r254624 --- gcc/fortran/ChangeLog | 7 +++++ gcc/fortran/trans-stmt.c | 5 ++-- gcc/testsuite/ChangeLog | 5 ++++ .../allocate_assumed_charlen_1.f90 | 28 +++++++++++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/allocate_assumed_charlen_1.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 7d016278b26..fb067aa3d6f 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,10 @@ +2017-11-10 Paul Thomas + + 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-09 Paul Thomas PR fortran/78619 diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c index d058e5f449d..ea0f9529f1c 100644 --- a/gcc/fortran/trans-stmt.c +++ b/gcc/fortran/trans-stmt.c @@ -5913,10 +5913,9 @@ gfc_trans_allocate (gfc_code * code) if (code->ext.alloc.ts.type != BT_CHARACTER) expr3_esize = TYPE_SIZE_UNIT ( gfc_typenode_for_spec (&code->ext.alloc.ts)); - else + else if (code->ext.alloc.ts.u.cl->length != NULL) { 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); @@ -5930,6 +5929,8 @@ gfc_trans_allocate (gfc_code * code) 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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a543e4fa404..620044a92a1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-11-10 Paul Thomas + + PR fortran/82934 + * gfortran.dg/allocate_assumed_charlen_1.f90: New test. + 2017-11-10 Jakub Jelinek PR bootstrap/82916 diff --git a/gcc/testsuite/gfortran.dg/allocate_assumed_charlen_1.f90 b/gcc/testsuite/gfortran.dg/allocate_assumed_charlen_1.f90 new file mode 100644 index 00000000000..382df36375d --- /dev/null +++ b/gcc/testsuite/gfortran.dg/allocate_assumed_charlen_1.f90 @@ -0,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 -- 2.30.2