aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran/expr.c
diff options
context:
space:
mode:
authorSandra Loosemore <sandra@codesourcery.com>2022-01-03 08:47:38 -0800
committerSandra Loosemore <sandra@codesourcery.com>2022-01-03 08:47:38 -0800
commit6447f6f983ffeaecb8753ef685d702bf2594968b (patch)
tree9594a3a4dd0b3474603be8838f7b6292ab6e6a23 /gcc/fortran/expr.c
parent6362627b27f395b054f359244fcfcb15ac0ac2ab (diff)
downloadgcc-6447f6f983ffeaecb8753ef685d702bf2594968b.zip
gcc-6447f6f983ffeaecb8753ef685d702bf2594968b.tar.gz
gcc-6447f6f983ffeaecb8753ef685d702bf2594968b.tar.bz2
Fortran: Fix array copy-in/copy-out for BIND(C) functions [PR103390]
The Fortran front end was generating invalid code for the array copy-out after a call to a BIND(C) function for a dummy with the CONTIGUOUS attribute when the actual argument was a call to the SHAPE intrinsic or other array expressions that are not lvalues. It was also generating code to evaluate the argument expression multiple times on copy-in. This patch teaches it to recognize that a copy is not needed in these cases. 2022-01-03 Sandra Loosemore <sandra@codesourcery.com> PR fortran/103390 gcc/fortran/ * expr.c (gfc_is_simply_contiguous): Make it smarter about function calls. * trans-expr.c (gfc_conv_gfc_desc_to_cfi_desc): Do not generate copy loops for array expressions that are not "variables" (lvalues). gcc/testsuite/ * gfortran.dg/c-interop/pr103390-1.f90: New. * gfortran.dg/c-interop/pr103390-2.f90: New. * gfortran.dg/c-interop/pr103390-3.f90: New. * gfortran.dg/c-interop/pr103390-4.f90: New. * gfortran.dg/c-interop/pr103390-6.f90: New. * gfortran.dg/c-interop/pr103390-7.f90: New. * gfortran.dg/c-interop/pr103390-8.f90: New. * gfortran.dg/c-interop/pr103390-9.f90: New.
Diffstat (limited to 'gcc/fortran/expr.c')
-rw-r--r--gcc/fortran/expr.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
index eb92527..96a2cd7 100644
--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -5883,8 +5883,16 @@ gfc_is_simply_contiguous (gfc_expr *expr, bool strict, bool permit_element)
if (expr->expr_type == EXPR_FUNCTION)
{
- if (expr->value.function.esym)
- return expr->value.function.esym->result->attr.contiguous;
+ if (expr->value.function.isym)
+ /* TRANSPOSE is the only intrinsic that may return a
+ non-contiguous array. It's treated as a special case in
+ gfc_conv_expr_descriptor too. */
+ return (expr->value.function.isym->id != GFC_ISYM_TRANSPOSE);
+ else if (expr->value.function.esym)
+ /* Only a pointer to an array without the contiguous attribute
+ can be non-contiguous as a result value. */
+ return (expr->value.function.esym->result->attr.contiguous
+ || !expr->value.function.esym->result->attr.pointer);
else
{
/* Type-bound procedures. */