From bdd82c9b9975a8bca850b99cd5cee75e6ed3c127 Mon Sep 17 00:00:00 2001 From: "Steven G. Kargl" Date: Wed, 10 Jan 2018 23:26:15 +0000 Subject: [PATCH] re PR fortran/82367 (ICE with deferred length string allocate on non-deferred length argument) 2018-01-10 Steven G. Kargl PR fortran/82367 * resolve.c (resolve_allocate_expr): Check for NULL pointer. 2018-01-10 Steven G. Kargl PR fortran/82367 * gfortran.dg/deferred_character_18.f90: New test. From-SVN: r256464 --- gcc/fortran/ChangeLog | 5 ++++ gcc/fortran/resolve.c | 9 ++++-- gcc/testsuite/ChangeLog | 5 ++++ .../gfortran.dg/deferred_character_18.f90 | 29 +++++++++++++++++++ 4 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/deferred_character_18.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 6bad1a6e1d2..f4289343cc1 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,8 @@ +2018-01-10 Steven G. Kargl + + PR fortran/82367 + * resolve.c (resolve_allocate_expr): Check for NULL pointer. + 2018-01-10 Steven G. Kargl PR fortran/83093 diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 195048354a8..e9f91d883ef 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -7484,8 +7484,13 @@ resolve_allocate_expr (gfc_expr *e, gfc_code *code, bool *array_alloc_wo_spec) if (code->ext.alloc.ts.type == BT_CHARACTER && !e->ts.deferred && !UNLIMITED_POLY (e)) { - int cmp = gfc_dep_compare_expr (e->ts.u.cl->length, - code->ext.alloc.ts.u.cl->length); + int cmp; + + if (!e->ts.u.cl->length) + goto failure; + + cmp = gfc_dep_compare_expr (e->ts.u.cl->length, + code->ext.alloc.ts.u.cl->length); if (cmp == 1 || cmp == -1 || cmp == -3) { gfc_error ("Allocating %s at %L with type-spec requires the same " diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 10273a9d8a6..4ac9461afd2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-01-10 Steven G. Kargl + + PR fortran/82367 + * gfortran.dg/deferred_character_18.f90: New test. + 2018-01-10 Martin Sebor PR tree-optimization/83671 diff --git a/gcc/testsuite/gfortran.dg/deferred_character_18.f90 b/gcc/testsuite/gfortran.dg/deferred_character_18.f90 new file mode 100644 index 00000000000..1b1457fa293 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/deferred_character_18.f90 @@ -0,0 +1,29 @@ +! { dg-do compile } +! PR Fortran/82367 +! Contributed by Walter Spector +module cls_allocmod + implicit none + +contains + + subroutine cls_alloc (n, str) + integer, intent(in) :: n + character(*), allocatable, intent(out) :: str +! Note: Star ^ should have been a colon (:) + + allocate (character(n)::str) + + end subroutine + +end module + +program cls + use cls_allocmod + implicit none + + character(:), allocatable :: s + + call cls_alloc(42, s) ! { dg-error "allocatable or pointer dummy argument" } + print *, 'string len =', len(s) + +end program -- 2.30.2