Hi, so attached is a quick and dirty solution for the allocatable return value problem. I personally don't like it. It is making a special case from the assign a function result to a variable. May be you have a better idea how to do this in gfortran style.
- Andre On Fri, 8 May 2015 15:31:46 +0200 Andre Vehreschild <ve...@gmx.de> wrote: > Hi Mikael, > > > > ?? I don't get you there? What do you mean? Do you think the > > > alloc_comp_class_3/4.* are not correctly testing the issue? Any idea of > > > how to test this better? I mean the pr is about this artificial > > > constructs. I merely struck it in search of a pr about allocatable > > > components. > > > > I was talking about the bug you found with t_init above. :-) > > the compiler is not ready to accept that function in a testcase. > > The alloc_omp_class_3/4 are fine. > > Oh, sorry, I misunderstood you there. Now let's see, where that one is hiding. > > - Andre -- Andre Vehreschild * Email: vehre ad gmx dot de
diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index 402d9b9..87e2cde 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -9043,6 +9043,7 @@ gfc_trans_assignment_1 (gfc_expr * expr1, gfc_expr * expr2, bool init_flag, stmtblock_t body; bool l_is_temp; bool scalar_to_array; + bool alloc_to_alloc; tree string_length; int n; @@ -9156,6 +9157,18 @@ gfc_trans_assignment_1 (gfc_expr * expr1, gfc_expr * expr2, bool init_flag, else gfc_conv_expr (&lse, expr1); + alloc_to_alloc = expr1->expr_type == EXPR_VARIABLE + && expr1->symtree->n.sym->ts.type == BT_DERIVED + && expr1->symtree->n.sym->attr.allocatable + && expr2->expr_type == EXPR_FUNCTION + && expr2->ts.type == BT_DERIVED + && expr2->value.function.esym->attr.allocatable; + if (alloc_to_alloc) + { + rse.expr = gfc_build_addr_expr (NULL_TREE, rse.expr); + lse.expr = gfc_build_addr_expr (NULL_TREE, lse.expr);; + } + /* Assignments of scalar derived types with allocatable components to arrays must be done with a deep copy and the rhs temporary must have its components deallocated afterwards. */ @@ -9208,7 +9221,8 @@ gfc_trans_assignment_1 (gfc_expr * expr1, gfc_expr * expr2, bool init_flag, if (lss == gfc_ss_terminator) { /* F2003: Add the code for reallocation on assignment. */ - if (flag_realloc_lhs && is_scalar_reallocatable_lhs (expr1)) + if (flag_realloc_lhs && !alloc_to_alloc + && is_scalar_reallocatable_lhs (expr1)) alloc_scalar_allocatable_for_assignment (&block, string_length, expr1, expr2);