From: Paul Thomas Date: Sun, 21 Oct 2018 17:32:06 +0000 (+0000) Subject: re PR fortran/71880 (pointer to allocatable character) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=88c08ac43c47bb5d21734be744df913dd568d108;p=gcc.git re PR fortran/71880 (pointer to allocatable character) 2018-10-21 Paul Thomas PR fortran/71880 * trans-expr.c (gfc_trans_pointer_assignment): Set the string length for array valued deferred length lhs. 2018-10-21 Paul Thomas PR fortran/71880 * gfortran.dg/deferred_character_31.f90 : New test. From-SVN: r265353 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 9ad52ca3c01..70ba4cce473 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2018-10-21 Paul Thomas + + PR fortran/71880 + * trans-expr.c (gfc_trans_pointer_assignment): Set the string + length for array valued deferred length lhs. + 2018-10-18 Tobias Burnus PR fortran/87625 diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index 7a5091b7f85..05b1d07eb02 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -8870,6 +8870,19 @@ gfc_trans_pointer_assignment (gfc_expr * expr1, gfc_expr * expr2) msg, rsize, lsize); } + if (expr1->ts.type == BT_CHARACTER + && expr1->symtree->n.sym->ts.deferred + && expr1->symtree->n.sym->ts.u.cl->backend_decl + && VAR_P (expr1->symtree->n.sym->ts.u.cl->backend_decl)) + { + tmp = expr1->symtree->n.sym->ts.u.cl->backend_decl; + if (expr2->expr_type != EXPR_NULL) + gfc_add_modify (&block, tmp, + fold_convert (TREE_TYPE (tmp), strlen_rhs)); + else + gfc_add_modify (&block, tmp, build_zero_cst (TREE_TYPE (tmp))); + } + gfc_add_block_to_block (&block, &lse.post); if (rank_remap) gfc_add_block_to_block (&block, &rse.post); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6e1c6844b42..c3ea50c8e3a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-10-21 Paul Thomas + + PR fortran/71880 + * gfortran.dg/deferred_character_31.f90 : New test. + 2018-10-21 H.J. Lu PR target/72782 diff --git a/gcc/testsuite/gfortran.dg/deferred_character_31.f90 b/gcc/testsuite/gfortran.dg/deferred_character_31.f90 new file mode 100644 index 00000000000..890b33e82df --- /dev/null +++ b/gcc/testsuite/gfortran.dg/deferred_character_31.f90 @@ -0,0 +1,16 @@ +! { dg-do } +! +! Test the fix for PR71880 in which the string length for 'p' +! was not set for the pointer assignment. +! +! Contributed by Valery Weber +! +program t + character(:), dimension(:), allocatable, target :: c + character(:), dimension(:), pointer :: p => NULL () + allocate(c, source = ['ABC','DEF','GHI']) + p => c + if (len(p) .ne. len (c)) stop 1 + if (size (p, 1) .ne. size (c, 1)) stop 2 + if (any (p .ne. c)) stop 3 +end program t