From 2294b6167ad8c2adbd54cdf0b69fe5a33809e129 Mon Sep 17 00:00:00 2001 From: pault Date: Sun, 8 Oct 2006 16:21:55 +0000 Subject: 2006-10-05 Erik Edelmann Paul Thomas PR fortran/20541 * interface.c (gfc_compare_derived_types): Add comparison of the allocatable field. * intrinsic.c (add_subroutines): Add MOVE_ALLOC. * trans-expr.c (gfc_conv_aliased_arg, gfc_trans_subarray_assign, gfc_trans_subcomponent_assign, gfc_conv_string_parameter, gfc_trans_scalar_assign): Add extra arguments l_is_temp and r_is_var to references to latter function. (gfc_conv_function_call): Add enum for types of argument and an associated variable parm_kind. Deallocate components of INTENT(OUT) and non-variable arrays. (gfc_trans_subcomponent_assign): Add block to assign arrays to allocatable components. (gfc_trans_scalar_assign): Add block to handle assignments of derived types with allocatable components, using the above new arguments to control allocation/deallocation of memory and the copying of allocated arrays. * trans-array.c (gfc_array_allocate): Remove old identification of pointer and replace with that of an allocatable array. Add nullify of structures with allocatable components. (gfc_conv_array_initializer): Treat EXPR_NULL. (gfc_conv_array_parameter): Deallocate allocatable components of non-variable structures. (gfc_trans_dealloc_allocated): Use second argument of library deallocate to inhibit, without error, freeing NULL pointers. (get_full_array_size): New function to return the size of a full array. (gfc_duplicate_allocatable): New function to allocate and copy allocated data. (structure_alloc_comps): New recursive function to deallocate, nullify or copy allocatable components. (gfc_nullify_alloc_comp, gfc_deallocate_alloc_comp, gfc_copy_alloc_comp): New interface functions to call previous. (gfc_trans_deferred_array): Add the code to nullify allocatable components, when entering scope, and to deallocate them on leaving. Do not call gfc_trans_static_array_pointer and return for structures with allocatable components and default initializers. * symbol.c (gfc_set_component_attr): Set allocatable field. (gfc_get_component_attr): Set the allocatable attribute. * intrinsic.h : Prototype for gfc_check_move_alloc. * decl.c (build_struct): Apply TR15581 constraints for allocatable components. (variable_decl): Default initializer is always NULL for allocatable components. (match_attr_spec): Allow, or not, allocatable components, according to the standard in force. * trans-array.h : Prototypes for gfc_nullify_alloc_comp, gfc_deallocate_alloc_comp, gfc_copy_alloc_comp and gfc_duplicate_allocatable. * gfortran.texi : Add mention of TR15581 extensions. * gfortran.h : Add attribute alloc_comp, add gfc_components field allocatable and add the prototype for gfc_expr_to_initialize. * trans-stmt.c (generate_loop_for_temp_to_lhs, generate_loop_for_rhs_to_temp, gfc_trans_where_assign, gfc_trans_where_3): Add extra arguments to calls to gfc_trans_scalar_assign and set appropriately. (gfc_trans_allocate): Nullify allocatable components. (gfc_trans_deallocate): Deallocate to ultimate allocatable components but stop at ultimate pointer components. * module.c (mio_symbol_attribute, mio_symbol_attribute, mio_component): Add module support for allocatable components. * trans-types.c (gfc_get_derived_type): Treat allocatable components. * trans.h : Add two boolean arguments to gfc_trans_scalar_assign. * resolve.c (resolve_structure_cons): Check conformance of constructor element and the component. (resolve_allocate_expr): Add expression to nullify the constructor expression for allocatable components. (resolve_transfer): Inhibit I/O of derived types with allocatable components. (resolve_fl_derived): Skip check of bounds of allocatable components. * trans-decl.c (gfc_get_symbol_decl): Add derived types with allocatable components to deferred variable. (gfc_trans_deferred_vars): Make calls for derived types with allocatable components to gfc_trans_deferred_array. (gfc_generate_function_code): Nullify allocatable component function result on entry. * parse.c (parse_derived): Set symbol attr.allocatable if allocatable components are present. * check.c (gfc_check_allocated): Enforce attr.allocatable for intrinsic arguments. (gfc_check_move_alloc): Check arguments of move_alloc. * primary.c (gfc_variable_attr): Set allocatable attribute. * intrinsic.texi : Add index entry and section for for move_alloc. PR fortran/29115 * resolve.c (resolve_structure_cons): It is an error if the pointer component elements of a derived type constructor are not pointer or target. PR fortran/29211 * trans-stmt.c (generate_loop_for_temp_to_lhs, generate_loop_for_rhs_to_temp): Provide a string length for the temporary by copying that of the other side of the scalar assignment. 2006-10-05 Paul Thomas Erik Edelmann PR libgfortran/20541 * Makefile.in : Add move_alloc. * intrinsics/move_alloc.c: New function. * Makefile.am : Add move_alloc. 2006-10-05 Erik Edelmann Paul Thomas PR fortran/20541 * gfortran.dg/alloc_comp_basics_1.f90: New test. * gfortran.dg/alloc_comp_basics_2.f90: New test. * gfortran.dg/alloc_comp_assign_1.f90: New test. * gfortran.dg/alloc_comp_assign_2.f90: New test. * gfortran.dg/alloc_comp_assign_3.f90: New test. * gfortran.dg/alloc_comp_assign_4.f90: New test. * gfortran.dg/alloc_comp_constraint_1.f90: New test. * gfortran.dg/alloc_comp_constraint_2.f90: New test. * gfortran.dg/alloc_comp_constraint_3.f90: New test. * gfortran.dg/alloc_comp_constructor_1.f90: New test. * gfortran.dg/alloc_comp_constructor_2.f90: New test. * gfortran.dg/alloc_comp_initializer_1.f90: New test. * gfortran.dg/alloc_comp_std.f90: New test. * gfortran.dg/move_alloc.f90: New test. PR fortran/29115 * gfortran.dg/derived_constructor_comps_2.f90: New test. PR fortran/29211 * gfortran.dg/forall_char_dependencies_1.f90: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@117558 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/fortran/trans-decl.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'gcc/fortran/trans-decl.c') diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index 43e27ee43e2..4d410b101a7 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -964,6 +964,9 @@ gfc_get_symbol_decl (gfc_symbol * sym) GFC_DECL_PACKED_ARRAY (decl) = 1; } + if (sym->ts.type == BT_DERIVED && sym->ts.derived->attr.alloc_comp) + gfc_defer_symbol_init (sym); + gfc_finish_var_decl (decl, sym); if (sym->ts.type == BT_CHARACTER) @@ -2572,6 +2575,8 @@ gfc_trans_deferred_vars (gfc_symbol * proc_sym, tree fnbody) for (sym = proc_sym->tlink; sym != proc_sym; sym = sym->tlink) { + bool sym_has_alloc_comp = (sym->ts.type == BT_DERIVED) + && sym->ts.derived->attr.alloc_comp; if (sym->attr.dimension) { switch (sym->as->type) @@ -2614,13 +2619,18 @@ gfc_trans_deferred_vars (gfc_symbol * proc_sym, tree fnbody) break; case AS_DEFERRED: - fnbody = gfc_trans_deferred_array (sym, fnbody); + if (!sym_has_alloc_comp) + fnbody = gfc_trans_deferred_array (sym, fnbody); break; default: gcc_unreachable (); } + if (sym_has_alloc_comp) + fnbody = gfc_trans_deferred_array (sym, fnbody); } + else if (sym_has_alloc_comp) + fnbody = gfc_trans_deferred_array (sym, fnbody); else if (sym->ts.type == BT_CHARACTER) { gfc_get_backend_locus (&loc); @@ -2972,10 +2982,12 @@ gfc_generate_function_code (gfc_namespace * ns) tree old_context; tree decl; tree tmp; + tree tmp2; stmtblock_t block; stmtblock_t body; tree result; gfc_symbol *sym; + int rank; sym = ns->proc_name; @@ -3135,7 +3147,6 @@ gfc_generate_function_code (gfc_namespace * ns) tmp = gfc_finish_block (&body); /* Add code to create and cleanup arrays. */ tmp = gfc_trans_deferred_vars (sym, tmp); - gfc_add_expr_to_block (&block, tmp); if (TREE_TYPE (DECL_RESULT (fndecl)) != void_type_node) { @@ -3150,7 +3161,18 @@ gfc_generate_function_code (gfc_namespace * ns) else result = sym->result->backend_decl; - if (result == NULL_TREE) + if (result != NULL_TREE && sym->attr.function + && sym->ts.type == BT_DERIVED + && sym->ts.derived->attr.alloc_comp) + { + rank = sym->as ? sym->as->rank : 0; + tmp2 = gfc_nullify_alloc_comp (sym->ts.derived, result, rank); + gfc_add_expr_to_block (&block, tmp2); + } + + gfc_add_expr_to_block (&block, tmp); + + if (result == NULL_TREE) warning (0, "Function return value not set"); else { @@ -3161,6 +3183,9 @@ gfc_generate_function_code (gfc_namespace * ns) gfc_add_expr_to_block (&block, tmp); } } + else + gfc_add_expr_to_block (&block, tmp); + /* Add all the decls we created during processing. */ decl = saved_function_decls; -- cgit v1.2.1