From 204d463084b323890918c66032fe8b582ea855d6 Mon Sep 17 00:00:00 2001 From: Paul Thomas Date: Sat, 22 Sep 2018 10:21:25 +0000 Subject: [PATCH] re PR fortran/85603 (ICE with character array substring assignment) 2018-09-22 Paul Thomas PR fortran/85603 * trans-array.c (gfc_alloc_allocatable_for_assignment): Test the charlen backend_decl before using the VAR_P macro. 2018-09-22 Paul Thomas PR fortran/85603 * gfortran.dg/deferred_character_23.f90 : New test. From-SVN: r264502 --- gcc/fortran/ChangeLog | 6 +++++ gcc/fortran/trans-array.c | 3 ++- gcc/testsuite/ChangeLog | 5 +++++ .../gfortran.dg/deferred_character_23.f90 | 22 +++++++++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/deferred_character_23.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index e6bf4294948..14a1de1da93 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2018-09-22 Paul Thomas + + PR fortran/85603 + * trans-array.c (gfc_alloc_allocatable_for_assignment): Test + the charlen backend_decl before using the VAR_P macro. + 2018-09-21 Paul Thomas PR fortran/77325 diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index 9e00eb0474f..0d699edba93 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -9950,7 +9950,8 @@ gfc_alloc_allocatable_for_assignment (gfc_loopinfo *loop, { if (expr2->ts.deferred) { - if (VAR_P (expr2->ts.u.cl->backend_decl)) + if (expr2->ts.u.cl->backend_decl + && VAR_P (expr2->ts.u.cl->backend_decl)) tmp = expr2->ts.u.cl->backend_decl; else tmp = rss->info->string_length; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7cba59c8347..78800e898c9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-09-22 Paul Thomas + + PR fortran/85603 + * gfortran.dg/deferred_character_23.f90 : New test. + 2018-09-21 Jeff Law * gcc.dg/tree-ssa/vrp113.c: Disable EVRP. diff --git a/gcc/testsuite/gfortran.dg/deferred_character_23.f90 b/gcc/testsuite/gfortran.dg/deferred_character_23.f90 new file mode 100644 index 00000000000..c018334688e --- /dev/null +++ b/gcc/testsuite/gfortran.dg/deferred_character_23.f90 @@ -0,0 +1,22 @@ +! { dg-do run } +! +! Tests the fix for PR85603. +! +! Contributed by Walt Spector +! +program strlen_bug + implicit none + + character(:), allocatable :: strings(:) + integer :: maxlen + + strings = [ character(32) :: & + 'short', & + 'somewhat longer' ] + maxlen = maxval (len_trim (strings)) + if (maxlen .ne. 15) stop 1 + strings = strings(:)(:maxlen) ! Used to ICE + if (any (strings .ne. ['short ','somewhat longer'])) stop 2 + + deallocate (strings) ! To check for memory leaks +end program -- 2.30.2