[multiple changes]
authorLouis Krupp <louis.krupp@zoho.com>
Fri, 7 Oct 2016 02:24:40 +0000 (02:24 +0000)
committerLouis Krupp <lkrupp@gcc.gnu.org>
Fri, 7 Oct 2016 02:24:40 +0000 (02:24 +0000)
2016-10-06  Louis Krupp <louis.krupp@zoho.com>

* gfortran.dg/pr69955.f90: New test.

2016-10-06  Louis Krupp  <louis.krupp@zoho.com>

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
gcc/fortran/trans-array.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/pr69955.f90 [new file with mode: 0644]

index 874779b92dd0fc49ff9b0075e75784c136b8a6e8..2b1b85c90fd50bd36210ec0469bd337d515ea826 100644 (file)
@@ -1,8 +1,14 @@
+2016-10-06  Louis Krupp  <louis.krupp@zoho.com>
+
+       PR fortran/69955
+       * trans-array.c (gfc_conv_expr_descriptor): Don't allocate
+       components if it's not necessary.
+
 2016-10-05  Louis Krupp  <louis.krupp@zoho.com>
 
        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  <kargls@gcc.gnu.org>
 
index 50312fed3074f01a6ff5dd4bcdf84e5d96ed58d9..37cca79faefe5953e61bc80615f728815ed22cf5 100644 (file)
@@ -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.  */
index 18c1a17242fbf3f054cd971b2ebfbac6210a8fbc..0728e02559ab0a225c68e548945ff046565687cf 100644 (file)
@@ -1,3 +1,7 @@
+2016-10-06  Louis Krupp <louis.krupp@zoho.com>
+
+       * gfortran.dg/pr69955.f90: New test.
+
 2016_10-06  Louis Krupp  <louis.krupp@zoho.com>
 
        PR fortran/57910
diff --git a/gcc/testsuite/gfortran.dg/pr69955.f90 b/gcc/testsuite/gfortran.dg/pr69955.f90
new file mode 100644 (file)
index 0000000..8b7852a
--- /dev/null
@@ -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" } }