aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorThomas Koenig <tkoenig@gcc.gnu.org>2019-01-13 11:06:03 +0000
committerThomas Koenig <tkoenig@gcc.gnu.org>2019-01-13 11:06:03 +0000
commit5f8865c358bed3c7f71329b429a617ad8150a042 (patch)
tree0a66079575ac33a1212be350cbd4d286af6fdfcd /gcc
parent264201216816c9145e40b856628a6c3e3eec6178 (diff)
downloadgcc-5f8865c358bed3c7f71329b429a617ad8150a042.zip
gcc-5f8865c358bed3c7f71329b429a617ad8150a042.tar.gz
gcc-5f8865c358bed3c7f71329b429a617ad8150a042.tar.bz2
re PR fortran/59345 (_gfortran_internal_pack on compiler generated temps)
2019-01-13 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/59345 * trans-array.c (gfc_conv_array_parameter): Remove TODO. Do not pack/unpack results of functions which return an explicit-shaped or allocatable array. 2019-01-13 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/59345 * gfortran.dg/internal_pack_17.f90: New test. * gfortran.dg/alloc_comp_auto_array_3.f90: Adjust number of calls to builtin_free. From-SVN: r267903
Diffstat (limited to 'gcc')
-rw-r--r--gcc/fortran/ChangeLog7
-rw-r--r--gcc/fortran/trans-array.c21
-rw-r--r--gcc/testsuite/ChangeLog7
-rw-r--r--gcc/testsuite/gfortran.dg/alloc_comp_auto_array_3.f902
-rw-r--r--gcc/testsuite/gfortran.dg/internal_pack_17.f9024
5 files changed, 55 insertions, 6 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 50db133..82e122e 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,10 @@
+2019-01-13 Thomas Koenig <tkoenig@gcc.gnu.org>
+
+ PR fortran/59345
+ * trans-array.c (gfc_conv_array_parameter): Remove TODO. Do not
+ pack/unpack results of functions which return an explicit-shaped
+ or allocatable array.
+
2019-01-12 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/61765
diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index 6b3c0e2..ae597e8 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -7756,7 +7756,6 @@ array_parameter_size (tree desc, gfc_expr *expr, tree *size)
}
/* Convert an array for passing as an actual parameter. */
-/* TODO: Optimize passing g77 arrays. */
void
gfc_conv_array_parameter (gfc_se * se, gfc_expr * expr, bool g77,
@@ -7882,11 +7881,23 @@ gfc_conv_array_parameter (gfc_se * se, gfc_expr * expr, bool g77,
no_pack = contiguous && no_pack;
- /* If we have an expression, an array temporary will be
- generated which does not need to be packed / unpacked
- if passed to an explicit-shape dummy array. */
+ /* If we have an EXPR_OP or a function returning an explicit-shaped
+ or allocatable array, an array temporary will be generated which
+ does not need to be packed / unpacked if passed to an
+ explicit-shape dummy array. */
- no_pack = no_pack || (g77 && expr->expr_type == EXPR_OP);
+ if (g77)
+ {
+ if (expr->expr_type == EXPR_OP)
+ no_pack = 1;
+ else if (expr->expr_type == EXPR_FUNCTION && expr->value.function.esym)
+ {
+ gfc_symbol *result = expr->value.function.esym->result;
+ if (result->attr.dimension
+ && (result->as->type == AS_EXPLICIT || result->attr.allocatable))
+ no_pack = 1;
+ }
+ }
/* Array constructors are always contiguous and do not need packing. */
array_constructor = g77 && !this_array_result && expr->expr_type == EXPR_ARRAY;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 0398fb8..609320e 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2019-01-13 Thomas Koenig <tkoenig@gcc.gnu.org>
+
+ PR fortran/59345
+ * gfortran.dg/internal_pack_17.f90: New test.
+ * gfortran.dg/alloc_comp_auto_array_3.f90: Adjust number of calls
+ to builtin_free.
+
2019-01-12 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/61765
diff --git a/gcc/testsuite/gfortran.dg/alloc_comp_auto_array_3.f90 b/gcc/testsuite/gfortran.dg/alloc_comp_auto_array_3.f90
index b135d3d..15f9ecb 100644
--- a/gcc/testsuite/gfortran.dg/alloc_comp_auto_array_3.f90
+++ b/gcc/testsuite/gfortran.dg/alloc_comp_auto_array_3.f90
@@ -26,5 +26,5 @@ contains
end function
end
! { dg-final { scan-tree-dump-times "builtin_malloc" 3 "original" } }
-! { dg-final { scan-tree-dump-times "builtin_free" 4 "original" } }
+! { dg-final { scan-tree-dump-times "builtin_free" 3 "original" } }
! { dg-final { scan-tree-dump-times "while \\(1\\)" 4 "original" } }
diff --git a/gcc/testsuite/gfortran.dg/internal_pack_17.f90 b/gcc/testsuite/gfortran.dg/internal_pack_17.f90
new file mode 100644
index 0000000..c1b813b
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/internal_pack_17.f90
@@ -0,0 +1,24 @@
+! { dg-do compile }
+! { dg-additional-options "-fdump-tree-original" }
+! PR 59345 - pack/unpack was not needed here.
+! Original test case by Joost VandeVondele
+SUBROUTINE S1(A)
+ INTERFACE
+ FUNCTION CONTIGUOUS_F1() RESULT(res)
+ INTEGER :: res(5)
+ END FUNCTION
+ END INTERFACE
+ CALL S2(CONTIGUOUS_F1())
+END SUBROUTINE
+
+SUBROUTINE S3(A)
+ INTERFACE
+ FUNCTION CONTIGOUOS_F2() RESULT(res)
+ INTEGER, ALLOCATABLE :: res(:)
+ END FUNCTION
+ END INTERFACE
+ PROCEDURE(CONTIGOUOS_F2), POINTER :: A
+ CALL S2(A())
+END SUBROUTINE
+! { dg-final { scan-tree-dump-not "_gfortran_internal_pack" "original" } }
+! { dg-final { scan-tree-dump-not "_gfortran_internal_unpack" "original" } }