aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran/expr.c
diff options
context:
space:
mode:
authorThomas König <tkoenig@gcc.gnu.org>2020-04-23 20:30:01 +0200
committerThomas König <tkoenig@gcc.gnu.org>2020-04-23 20:30:01 +0200
commit06eca1acafa27e19e82dc73927394a7a4d0bdbc5 (patch)
tree4c1c6756bd17f5900f4ee9ff8d9386336cae1533 /gcc/fortran/expr.c
parentdcf69ac5448fd6a16137cfe9fe6deadd0ec0243d (diff)
downloadgcc-06eca1acafa27e19e82dc73927394a7a4d0bdbc5.zip
gcc-06eca1acafa27e19e82dc73927394a7a4d0bdbc5.tar.gz
gcc-06eca1acafa27e19e82dc73927394a7a4d0bdbc5.tar.bz2
Fix PR 93956, wrong pointer when returned via function.
This one took a bit of detective work. When array pointers point to components of derived types, we currently set the span field and then create an array temporary when we pass the array pointer to a procedure as a non-pointer or non-target argument. (This is inefficient, but that's for another release). Now, the compiler detected this case when there was a direct assignment like p => a%b, but not when p was returned either as a function result or via an argument. This patch fixes that. 2020-04-23 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/93956 * expr.c (gfc_check_pointer_assign): Also set subref_array_pointer when a function returns a pointer. * interface.c (gfc_set_subref_array_pointer_arg): New function. (gfc_procedure_use): Call it. 2020-04-23 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/93956 * gfortran.dg/pointer_assign_13.f90: New test.
Diffstat (limited to 'gcc/fortran/expr.c')
-rw-r--r--gcc/fortran/expr.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
index a9fa03a..618c98a 100644
--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -4242,8 +4242,11 @@ gfc_check_pointer_assign (gfc_expr *lvalue, gfc_expr *rvalue,
if (rvalue->expr_type == EXPR_NULL)
return true;
- if (rvalue->expr_type == EXPR_VARIABLE && is_subref_array (rvalue))
- lvalue->symtree->n.sym->attr.subref_array_pointer = 1;
+ /* A function may also return subref arrray pointer. */
+
+ if ((rvalue->expr_type == EXPR_VARIABLE && is_subref_array (rvalue))
+ || rvalue->expr_type == EXPR_FUNCTION)
+ lvalue->symtree->n.sym->attr.subref_array_pointer = 1;
attr = gfc_expr_attr (rvalue);