From: Paul Thomas Date: Sat, 5 Nov 2016 07:11:24 +0000 (+0000) Subject: re PR fortran/67564 (Segfault on sourced allocattion statement with class(*) arrays) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d233ee5f50926d58da601e4f8633d98632ced3d2;p=gcc.git re PR fortran/67564 (Segfault on sourced allocattion statement with class(*) arrays) 2016-11-05 Paul Thomas PR fortran/67564 * trans-expr.c (gfc_conv_class_to_class): Return _len component of unlimited polymorphic entities. 2016-11-05 Paul Thomas PR fortran/67564 * gfortran.dg/select_type_39.f03: New test. From-SVN: r241869 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index f6b739c84eb..bf85619bcc9 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,4 +1,10 @@ -2016-04-19 Paul Thomas +2016-11-05 Paul Thomas + + PR fortran/67564 + * trans-expr.c (gfc_conv_class_to_class): Return _len component + of unlimited polymorphic entities. + +2016-11-04 Paul Thomas PR fortran/64933 * primary.c (gfc_match_varspec): If selector expression is diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index 7159b172eea..309f5023ab4 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -1091,6 +1091,12 @@ gfc_conv_class_to_class (gfc_se *parmse, gfc_expr *e, gfc_typespec class_ts, tmp = integer_zero_node; gfc_add_modify (&parmse->pre, ctree, fold_convert (TREE_TYPE (ctree), tmp)); + + /* Return the len component, except in the case of scalarized array + references, where the dynamic type cannot change. */ + if (!elemental && full_array && copyback) + gfc_add_modify (&parmse->post, tmp, + fold_convert (TREE_TYPE (tmp), ctree)); } if (optional) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3babf14777b..4369222f1d4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,4 +1,9 @@ -2016-04-19 Paul Thomas +2016-11-05 Paul Thomas + + PR fortran/67564 + * gfortran.dg/select_type_39.f03: New test. + +2016-11-04 Paul Thomas PR fortran/64933 * gfortran.dg/associate_23.f90: New test. diff --git a/gcc/testsuite/gfortran.dg/select_type_39.f03 b/gcc/testsuite/gfortran.dg/select_type_39.f03 new file mode 100644 index 00000000000..08d619536ab --- /dev/null +++ b/gcc/testsuite/gfortran.dg/select_type_39.f03 @@ -0,0 +1,20 @@ +! { dg-do run } +! +! Tests the fix for PR67564 comment #9. +! +! Contributed by Neil Carlson +! +class(*), allocatable :: val(:) +call get_value (val) +select type (val) +type is (character(*)) + if (size (val) .ne. 2) call abort + if (len(val) .ne. 3) call abort + if (any (val .ne. ['foo','bar'])) call abort +end select +contains + subroutine get_value (value) + class(*), allocatable, intent(out) :: value(:) + allocate(value, source=['foo','bar']) + end subroutine +end