From 4ee822df35cf031573ff85e05494afebacf9779a Mon Sep 17 00:00:00 2001 From: Louis Krupp Date: Fri, 7 Oct 2016 02:24:40 +0000 Subject: [PATCH] [multiple changes] 2016-10-06 Louis Krupp * gfortran.dg/pr69955.f90: New test. 2016-10-06 Louis Krupp PR fortran/69955 * trans-array.c (gfc_conv_expr_descriptor): Don't allocate components if it's not necessary. From-SVN: r240851 --- gcc/fortran/ChangeLog | 8 +++++- gcc/fortran/trans-array.c | 8 ++++-- gcc/testsuite/ChangeLog | 4 +++ gcc/testsuite/gfortran.dg/pr69955.f90 | 49 +++++++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr69955.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 874779b..2b1b85c 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,8 +1,14 @@ +2016-10-06 Louis Krupp + + PR fortran/69955 + * trans-array.c (gfc_conv_expr_descriptor): Don't allocate + components if it's not necessary. + 2016-10-05 Louis Krupp PR fortran/57910 * trans-expr.c (gfc_add_interface_mapping): Don't try to - dereference call-by-value scalar argument + dereference call-by-value scalar argument. 2016-10-05 Steven G. Kargl diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index 50312fe..37cca79 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -6963,6 +6963,7 @@ gfc_conv_expr_descriptor (gfc_se *se, gfc_expr *expr) /* TODO: Optimize passing function return values. */ gfc_se lse; gfc_se rse; + bool deep_copy; /* Start the copying loops. */ gfc_mark_ss_chain_used (loop.temp_ss, 1); @@ -6993,9 +6994,12 @@ gfc_conv_expr_descriptor (gfc_se *se, gfc_expr *expr) gfc_add_block_to_block (&block, &lse.pre); lse.string_length = rse.string_length; + + deep_copy = !se->data_not_needed + && (expr->expr_type == EXPR_VARIABLE + || expr->expr_type == EXPR_ARRAY); tmp = gfc_trans_scalar_assign (&lse, &rse, expr->ts, - expr->expr_type == EXPR_VARIABLE - || expr->expr_type == EXPR_ARRAY, false); + deep_copy, false); gfc_add_expr_to_block (&block, tmp); /* Finish the copying loops. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 18c1a17..0728e02 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2016-10-06 Louis Krupp + + * gfortran.dg/pr69955.f90: New test. + 2016_10-06 Louis Krupp PR fortran/57910 diff --git a/gcc/testsuite/gfortran.dg/pr69955.f90 b/gcc/testsuite/gfortran.dg/pr69955.f90 new file mode 100644 index 0000000..8b7852a --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr69955.f90 @@ -0,0 +1,49 @@ +! { dg-do run } +! { dg-options "-fdump-tree-original" } + +program p + implicit none + + type :: t1 + integer, allocatable :: t(:) + end type t1 + + type :: t2 + type(t1), allocatable :: x1(:) + end type t2 + + type(t2) :: var(10) + + integer :: i + + do i= 1, 10 + allocate(var(i)%x1(100)) + allocate(var(i)%x1(1)%t(100)) + enddo + + open(unit = 37, file = "/dev/null", status = "old") + + call s(1) + + close(unit = 37) + + do i=1,10 + deallocate(var(i)%x1) + enddo + +contains + + subroutine s(counter) + implicit none + integer, intent(in) :: counter + integer :: i, j, n + + do j=1, counter + n = size( [ ( var(i)%x1 , i = 1, size(var) ) ] ) + write(unit = 37, fmt = '(i5)') n + enddo + end subroutine + +end program p +! { dg-final { scan-tree-dump-times "__builtin_malloc" 4 "original" } } +! { dg-final { scan-tree-dump-times "__builtin_free" 4 "original" } } -- 2.7.4