From bdfd2ff072c47616e8e34dd99abf00df4cff3e51 Mon Sep 17 00:00:00 2001 From: Thomas Koenig Date: Thu, 24 Jul 2008 09:26:43 +0000 Subject: [PATCH] re PR fortran/29952 (Flag to give runtime information " array temporary was created for argument") 2008-07-24 Thomas Koenig PR fortran/29952 * gfortran.h: Add "warn_array_temp" to gfc_option_t. * lang.opt: Add -Warray-temporaries. * invoke.texi: Document -Warray-temporaries * trans-array.h (gfc_trans_create_temp_array): Add argument of type *locus. (gfc_conv_loop_setup): Likewise. * trans-array.c (gfc_trans_create_temp_array): If -Warray-temporaries is given and locus is present, warn about creation of array temporaries. (gfc_trans_array_constructor_subarray): Add locus to call of gfc_conv_loop_setup. (gfc_trans_array_constructor): Add where argument. Pass where argument to call of gfc_trans_create_temp_array. (gfc_add_loop_ss_code): Add where argument. Pass where argument to recursive call of gfc_add_loop_ss_code and to call of gfc_trans_array_constructor. (gfc_conv_loop_setup): Add where argument. Pass where argument to calls to gfc_add_loop_ss_code and to gfc_trans_create_temp_array. (gfc_conv_expr_descriptor): Pass location to call of gfc_conv_loop_setup. (gfc_conv_array_parameter): If -Warray-temporaries is given, warn about creation of temporary arrays. * trans-expr.c (gfc_conv_subref_array_arg): Add where argument to call to gfc_conv_loop_setup. (gfc_conv_function_call): Add where argument to call to gfc_trans_creat_temp_array. (gfc_trans_subarray_assign): Likewise. (gfc_trans_assignment_1): Add where argument to call to gfc_conv_loop_setup. * trans-stmt.c (gfc_conv_elemental_dependencies): Add where argument to call to gfc_trans_create_temp_array. (gfc_trans_call): Add where argument to call to gfc_conv_loop_setup. (generate_loop_for_temp_to_lhs): Likewise. (generate_loop_for_rhs_to_temp): Likewise. (compute_inner_temp_size): Likewise. (gfc_trans-pointer_assign_need_temp): Likewise. (gfc_evaluate_where_mask): Likewise. (gfc_trans_where_assign): Likewise. (gfc_trans_where_3): Likewise. * trans-io.c (transfer_srray_component): Add where argument to function. Add where argument to call to gfc_conv_loop_setup. (transfer_expr): Add where argument to call to transfer_array_component. (gfc_trans_transfer): Add where expression to call to gfc_conv_loop_setup. * trans-intrinsic.c (gfc_conv_intrinsic_anyall): Add where argument to call to gfc_conv_loop_setup. (gfc_conv_intrinsic_count): Likewise. (gfc_conv_intrinsic_arith): Likewise. (gfc_conv_intrinsic_dot_product): Likewise. (gfc_conv_intrinsic_minmaxloc): Likewise. (gfc_conv_intrinsic_minmaxval): Likewise. (gfc_conv_intrinsic_array_transfer): Warn about creation of temporary array. Add where argument to call to gfc_trans_create_temp_array. * options.c (gfc_init_options): Initialize gfc_option.warn_array_temp. (gfc_handle_option): Set gfc_option.warn_array_temp. 2008-07-24 Thomas Koenig PR fortran/29952 * gfortran.dg/array_temporaries_1.f90: New test case. From-SVN: r138112 --- gcc/fortran/ChangeLog | 61 +++++++++++++++++++ gcc/fortran/gfortran.h | 1 + gcc/fortran/invoke.texi | 13 +++- gcc/fortran/lang.opt | 4 ++ gcc/fortran/options.c | 5 ++ gcc/fortran/trans-array.c | 35 +++++++---- gcc/fortran/trans-array.h | 5 +- gcc/fortran/trans-expr.c | 11 ++-- gcc/fortran/trans-intrinsic.c | 19 +++--- gcc/fortran/trans-io.c | 8 +-- gcc/fortran/trans-stmt.c | 19 +++--- gcc/testsuite/ChangeLog | 5 ++ .../gfortran.dg/array_temporaries_1.f90 | 19 ++++++ 13 files changed, 164 insertions(+), 41 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/array_temporaries_1.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 7e3ffd65c93..1f0ba0d3487 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,64 @@ +2008-07-24 Thomas Koenig + + PR fortran/29952 + * gfortran.h: Add "warn_array_temp" to gfc_option_t. + * lang.opt: Add -Warray-temporaries. + * invoke.texi: Document -Warray-temporaries + * trans-array.h (gfc_trans_create_temp_array): Add argument of + type *locus. + (gfc_conv_loop_setup): Likewise. + * trans-array.c (gfc_trans_create_temp_array): If + -Warray-temporaries is given and locus is present, warn about + creation of array temporaries. + (gfc_trans_array_constructor_subarray): Add locus to call + of gfc_conv_loop_setup. + (gfc_trans_array_constructor): Add where argument. Pass where + argument to call of gfc_trans_create_temp_array. + (gfc_add_loop_ss_code): Add where argument. Pass where argument + to recursive call of gfc_add_loop_ss_code and to call of + gfc_trans_array_constructor. + (gfc_conv_loop_setup): Add where argument. Pass where argument + to calls to gfc_add_loop_ss_code and to gfc_trans_create_temp_array. + (gfc_conv_expr_descriptor): Pass location to call of + gfc_conv_loop_setup. + (gfc_conv_array_parameter): If -Warray-temporaries is given, + warn about creation of temporary arrays. + * trans-expr.c (gfc_conv_subref_array_arg): Add where argument + to call to gfc_conv_loop_setup. + (gfc_conv_function_call): Add where argument to call to + gfc_trans_creat_temp_array. + (gfc_trans_subarray_assign): Likewise. + (gfc_trans_assignment_1): Add where argument to call to + gfc_conv_loop_setup. + * trans-stmt.c (gfc_conv_elemental_dependencies): Add where + argument to call to gfc_trans_create_temp_array. + (gfc_trans_call): Add where argument to call to gfc_conv_loop_setup. + (generate_loop_for_temp_to_lhs): Likewise. + (generate_loop_for_rhs_to_temp): Likewise. + (compute_inner_temp_size): Likewise. + (gfc_trans-pointer_assign_need_temp): Likewise. + (gfc_evaluate_where_mask): Likewise. + (gfc_trans_where_assign): Likewise. + (gfc_trans_where_3): Likewise. + * trans-io.c (transfer_srray_component): Add where argument + to function. Add where argument to call to gfc_conv_loop_setup. + (transfer_expr): Add where argument to call to + transfer_array_component. + (gfc_trans_transfer): Add where expression to call to + gfc_conv_loop_setup. + * trans-intrinsic.c (gfc_conv_intrinsic_anyall): Add + where argument to call to gfc_conv_loop_setup. + (gfc_conv_intrinsic_count): Likewise. + (gfc_conv_intrinsic_arith): Likewise. + (gfc_conv_intrinsic_dot_product): Likewise. + (gfc_conv_intrinsic_minmaxloc): Likewise. + (gfc_conv_intrinsic_minmaxval): Likewise. + (gfc_conv_intrinsic_array_transfer): Warn about + creation of temporary array. + Add where argument to call to gfc_trans_create_temp_array. + * options.c (gfc_init_options): Initialize gfc_option.warn_array_temp. + (gfc_handle_option): Set gfc_option.warn_array_temp. + 2008-07-23 Manuel Lopez-Ibanez PR 35058 diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index 2c284657a09..c8afd6623fd 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -1873,6 +1873,7 @@ typedef struct int warn_tabs; int warn_underflow; int warn_character_truncation; + int warn_array_temp; int max_errors; int flag_all_intrinsics; diff --git a/gcc/fortran/invoke.texi b/gcc/fortran/invoke.texi index 445b4a7d1a9..df9019c7660 100644 --- a/gcc/fortran/invoke.texi +++ b/gcc/fortran/invoke.texi @@ -137,9 +137,9 @@ by type. Explanations are in the following sections. and warnings}. @gccoptlist{-fmax-errors=@var{n} @gol -fsyntax-only -pedantic -pedantic-errors @gol --Wall -Waliasing -Wampersand -Wcharacter-truncation -Wconversion @gol --Wimplicit-interface -Wline-truncation -Wnonstd-intrinsics -Wsurprising @gol --Wno-tabs -Wunderflow -Wunused-parameter} +-Wall -Waliasing -Wampersand -Warray-bounds -Wcharacter-truncation @gol +-Wconversion -Wimplicit-interface -Wline-truncation -Wnonstd-intrinsics @gol +-Wsurprising -Wno-tabs -Wunderflow -Wunused-parameter} @item Debugging Options @xref{Debugging Options,,Options for debugging your program or GNU Fortran}. @@ -698,6 +698,13 @@ given in a continued character constant, GNU Fortran assumes continuation at the first non-comment, non-whitespace character after the ampersand that initiated the continuation. +@item -Warray-temporaries +@opindex @code{Warray-temporaries} +@cindex warnings, array temporaries +Warn about array temporaries generated by the compiler. The information +generated by this warning is sometimes useful in optimization, in order to +avoid such temporaries. + @item -Wcharacter-truncation @opindex @code{Wcharacter-truncation} @cindex warnings, character truncation diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt index f0f6c6a756d..468d72cf89d 100644 --- a/gcc/fortran/lang.opt +++ b/gcc/fortran/lang.opt @@ -76,6 +76,10 @@ Wampersand Fortran Warning Warn about missing ampersand in continued character constants +Warray-temporaries +Fortran Warning +Warn about creation of array temporaries + Wcharacter-truncation Fortran Warning Warn about truncated character expressions diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c index 8480364bc52..ca023a055e0 100644 --- a/gcc/fortran/options.c +++ b/gcc/fortran/options.c @@ -69,6 +69,7 @@ gfc_init_options (unsigned int argc, const char **argv) gfc_option.warn_aliasing = 0; gfc_option.warn_ampersand = 0; gfc_option.warn_character_truncation = 0; + gfc_option.warn_array_temp = 0; gfc_option.warn_conversion = 0; gfc_option.warn_implicit_interface = 0; gfc_option.warn_line_truncation = 0; @@ -485,6 +486,10 @@ gfc_handle_option (size_t scode, const char *arg, int value) gfc_option.warn_ampersand = value; break; + case OPT_Warray_temporaries: + gfc_option.warn_array_temp = value; + break; + case OPT_Wcharacter_truncation: gfc_option.warn_character_truncation = value; break; diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index 6402887cec8..9ec8406c428 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -576,7 +576,7 @@ tree gfc_trans_create_temp_array (stmtblock_t * pre, stmtblock_t * post, gfc_loopinfo * loop, gfc_ss_info * info, tree eltype, bool dynamic, bool dealloc, - bool callee_alloc) + bool callee_alloc, locus * where) { tree type; tree desc; @@ -589,6 +589,10 @@ gfc_trans_create_temp_array (stmtblock_t * pre, stmtblock_t * post, int dim; gcc_assert (info->dimen > 0); + + if (gfc_option.warn_array_temp && where) + gfc_warning ("Creating array temporary at %L", where); + /* Set the lower bound to zero. */ for (dim = 0; dim < info->dimen; dim++) { @@ -1070,7 +1074,7 @@ gfc_trans_array_constructor_subarray (stmtblock_t * pblock, /* Initialize the loop. */ gfc_conv_ss_startstride (&loop); - gfc_conv_loop_setup (&loop); + gfc_conv_loop_setup (&loop, &expr->where); /* Make sure the constructed array has room for the new data. */ if (dynamic) @@ -1683,7 +1687,7 @@ constant_array_constructor_loop_size (gfc_loopinfo * loop) simplest method. */ static void -gfc_trans_array_constructor (gfc_loopinfo * loop, gfc_ss * ss) +gfc_trans_array_constructor (gfc_loopinfo * loop, gfc_ss * ss, locus * where) { gfc_constructor *c; tree offset; @@ -1809,7 +1813,7 @@ gfc_trans_array_constructor (gfc_loopinfo * loop, gfc_ss * ss) loopfrom = NULL_TREE; gfc_trans_create_temp_array (&loop->pre, &loop->post, loop, &ss->data.info, - type, dynamic, true, false); + type, dynamic, true, false, where); if (loopfrom != NULL_TREE) { @@ -1896,7 +1900,8 @@ gfc_set_vector_loop_bounds (gfc_loopinfo * loop, gfc_ss_info * info) but before the actual scalarizing loops. */ static void -gfc_add_loop_ss_code (gfc_loopinfo * loop, gfc_ss * ss, bool subscript) +gfc_add_loop_ss_code (gfc_loopinfo * loop, gfc_ss * ss, bool subscript, + locus * where) { gfc_se se; int n; @@ -1950,7 +1955,8 @@ gfc_add_loop_ss_code (gfc_loopinfo * loop, gfc_ss * ss, bool subscript) /* Add the expressions for scalar and vector subscripts. */ for (n = 0; n < GFC_MAX_DIMENSIONS; n++) if (ss->data.info.subscript[n]) - gfc_add_loop_ss_code (loop, ss->data.info.subscript[n], true); + gfc_add_loop_ss_code (loop, ss->data.info.subscript[n], true, + where); gfc_set_vector_loop_bounds (loop, &ss->data.info); break; @@ -1993,7 +1999,7 @@ gfc_add_loop_ss_code (gfc_loopinfo * loop, gfc_ss * ss, bool subscript) gfc_add_block_to_block (&loop->pre, &se.pre); gfc_add_block_to_block (&loop->post, &se.post); } - gfc_trans_array_constructor (loop, ss); + gfc_trans_array_constructor (loop, ss, where); break; case GFC_SS_TEMP: @@ -3327,7 +3333,7 @@ gfc_conv_resolve_dependencies (gfc_loopinfo * loop, gfc_ss * dest, moved outside the loop. */ void -gfc_conv_loop_setup (gfc_loopinfo * loop) +gfc_conv_loop_setup (gfc_loopinfo * loop, locus * where) { int n; int dim; @@ -3493,7 +3499,7 @@ gfc_conv_loop_setup (gfc_loopinfo * loop) /* Add all the scalar code that can be taken out of the loops. This may include calculating the loop bounds, so do it before allocating the temporary. */ - gfc_add_loop_ss_code (loop, loop->ss, false); + gfc_add_loop_ss_code (loop, loop->ss, false, where); /* If we want a temporary then create it. */ if (loop->temp_ss != NULL) @@ -3515,7 +3521,7 @@ gfc_conv_loop_setup (gfc_loopinfo * loop) loop->temp_ss->data.info.dimen = n; gfc_trans_create_temp_array (&loop->pre, &loop->post, loop, &loop->temp_ss->data.info, tmp, false, true, - false); + false, where); } for (n = 0; n < loop->temp_dim; n++) @@ -4299,6 +4305,9 @@ gfc_trans_dummy_array_bias (gfc_symbol * sym, tree tmpdesc, tree body) stmt_unpacked = build_call_expr (gfor_fndecl_in_pack, 1, tmp); stride = gfc_index_one_node; + + if (gfc_option.warn_array_temp) + gfc_warning ("Creating array temporary at %L", &loc); } /* This is for the case where the array data is used directly without @@ -4871,7 +4880,7 @@ gfc_conv_expr_descriptor (gfc_se * se, gfc_expr * expr, gfc_ss * ss) gfc_add_ss_to_loop (&loop, loop.temp_ss); } - gfc_conv_loop_setup (&loop); + gfc_conv_loop_setup (&loop, & expr->where); if (need_tmp) { @@ -5219,6 +5228,10 @@ gfc_conv_array_parameter (gfc_se * se, gfc_expr * expr, gfc_ss * ss, int g77) { desc = se->expr; /* Repack the array. */ + + if (gfc_option.warn_array_temp) + gfc_warning ("Creating array temporary at %L", &expr->where); + ptr = build_call_expr (gfor_fndecl_in_pack, 1, desc); ptr = gfc_evaluate_now (ptr, &se->pre); se->expr = ptr; diff --git a/gcc/fortran/trans-array.h b/gcc/fortran/trans-array.h index 2b644c7880b..1e34c9a9f28 100644 --- a/gcc/fortran/trans-array.h +++ b/gcc/fortran/trans-array.h @@ -32,7 +32,8 @@ void gfc_set_loop_bounds_from_array_spec (gfc_interface_mapping *, /* Generate code to create a temporary array. */ tree gfc_trans_create_temp_array (stmtblock_t *, stmtblock_t *, gfc_loopinfo *, - gfc_ss_info *, tree, bool, bool, bool); + gfc_ss_info *, tree, bool, bool, bool, + locus *); /* Generate function entry code for allocation of compiler allocated array variables. */ @@ -88,7 +89,7 @@ void gfc_trans_scalarizing_loops (gfc_loopinfo *, stmtblock_t *); /* Mark the end of the main loop body and the start of the copying loop. */ void gfc_trans_scalarized_loop_boundary (gfc_loopinfo *, stmtblock_t *); /* Initialize the scalarization loop parameters. */ -void gfc_conv_loop_setup (gfc_loopinfo *); +void gfc_conv_loop_setup (gfc_loopinfo *, locus *); /* Resolve array assignment dependencies. */ void gfc_conv_resolve_dependencies (gfc_loopinfo *, gfc_ss *, gfc_ss *); /* Build a null array descriptor constructor. */ diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index b5c9cdda0c6..3240d7f678c 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -2059,7 +2059,7 @@ gfc_conv_subref_array_arg (gfc_se * parmse, gfc_expr * expr, gfc_add_ss_to_loop (&loop, loop.temp_ss); /* Setup the scalarizing loops. */ - gfc_conv_loop_setup (&loop); + gfc_conv_loop_setup (&loop, &expr->where); /* Pass the temporary descriptor back to the caller. */ info = &loop.temp_ss->data.info; @@ -2124,7 +2124,7 @@ gfc_conv_subref_array_arg (gfc_se * parmse, gfc_expr * expr, gfc_conv_ss_startstride (&loop2); /* Setup the scalarizing loops. */ - gfc_conv_loop_setup (&loop2); + gfc_conv_loop_setup (&loop2, &expr->where); gfc_copy_loopinfo_to_se (&lse, &loop2); gfc_copy_loopinfo_to_se (&rse, &loop2); @@ -2717,7 +2717,8 @@ gfc_conv_function_call (gfc_se * se, gfc_symbol * sym, mustn't be deallocated. */ callee_alloc = sym->attr.allocatable || sym->attr.pointer; gfc_trans_create_temp_array (&se->pre, &se->post, se->loop, info, tmp, - false, !sym->attr.pointer, callee_alloc); + false, !sym->attr.pointer, callee_alloc, + &se->ss->expr->where); /* Pass the temporary as the first argument. */ tmp = info->descriptor; @@ -3335,7 +3336,7 @@ gfc_trans_subarray_assign (tree dest, gfc_component * cm, gfc_expr * expr) gfc_conv_ss_startstride (&loop); /* Setup the scalarizing loops. */ - gfc_conv_loop_setup (&loop); + gfc_conv_loop_setup (&loop, &expr->where); /* Setup the gfc_se structures. */ gfc_copy_loopinfo_to_se (&lse, &loop); @@ -4415,7 +4416,7 @@ gfc_trans_assignment_1 (gfc_expr * expr1, gfc_expr * expr2, bool init_flag) /* Resolve any data dependencies in the statement. */ gfc_conv_resolve_dependencies (&loop, lss, rss); /* Setup the scalarizing loops. */ - gfc_conv_loop_setup (&loop); + gfc_conv_loop_setup (&loop, &expr2->where); /* Setup the gfc_se structures. */ gfc_copy_loopinfo_to_se (&lse, &loop); diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c index 92bc0bb6d51..b76dd76ce9c 100644 --- a/gcc/fortran/trans-intrinsic.c +++ b/gcc/fortran/trans-intrinsic.c @@ -1731,7 +1731,7 @@ gfc_conv_intrinsic_anyall (gfc_se * se, gfc_expr * expr, int op) /* Initialize the loop. */ gfc_conv_ss_startstride (&loop); - gfc_conv_loop_setup (&loop); + gfc_conv_loop_setup (&loop, &expr->where); gfc_mark_ss_chain_used (arrayss, 1); /* Generate the loop body. */ @@ -1813,7 +1813,7 @@ gfc_conv_intrinsic_count (gfc_se * se, gfc_expr * expr) /* Initialize the loop. */ gfc_conv_ss_startstride (&loop); - gfc_conv_loop_setup (&loop); + gfc_conv_loop_setup (&loop, &expr->where); gfc_mark_ss_chain_used (arrayss, 1); /* Generate the loop body. */ @@ -1901,7 +1901,7 @@ gfc_conv_intrinsic_arith (gfc_se * se, gfc_expr * expr, int op) /* Initialize the loop. */ gfc_conv_ss_startstride (&loop); - gfc_conv_loop_setup (&loop); + gfc_conv_loop_setup (&loop, &expr->where); gfc_mark_ss_chain_used (arrayss, 1); if (maskss) @@ -2019,7 +2019,7 @@ gfc_conv_intrinsic_dot_product (gfc_se * se, gfc_expr * expr) /* Initialize the loop. */ gfc_conv_ss_startstride (&loop); - gfc_conv_loop_setup (&loop); + gfc_conv_loop_setup (&loop, &expr->where); gfc_mark_ss_chain_used (arrayss1, 1); gfc_mark_ss_chain_used (arrayss2, 1); @@ -2159,7 +2159,7 @@ gfc_conv_intrinsic_minmaxloc (gfc_se * se, gfc_expr * expr, int op) /* Initialize the loop. */ gfc_conv_ss_startstride (&loop); - gfc_conv_loop_setup (&loop); + gfc_conv_loop_setup (&loop, &expr->where); gcc_assert (loop.dimen == 1); @@ -2355,7 +2355,7 @@ gfc_conv_intrinsic_minmaxval (gfc_se * se, gfc_expr * expr, int op) /* Initialize the loop. */ gfc_conv_ss_startstride (&loop); - gfc_conv_loop_setup (&loop); + gfc_conv_loop_setup (&loop, &expr->where); gfc_mark_ss_chain_used (arrayss, 1); if (maskss) @@ -3434,6 +3434,10 @@ gfc_conv_intrinsic_array_transfer (gfc_se * se, gfc_expr * expr) && arg->expr->ref->u.ar.type == AR_FULL)) { tmp = build_fold_addr_expr (argse.expr); + + if (gfc_option.warn_array_temp) + gfc_warning ("Creating array temporary at %L", &expr->where); + source = build_call_expr (gfor_fndecl_in_pack, 1, tmp); source = gfc_evaluate_now (source, &argse.pre); @@ -3587,7 +3591,8 @@ gfc_conv_intrinsic_array_transfer (gfc_se * se, gfc_expr * expr) FIXME callee_alloc is not set! */ gfc_trans_create_temp_array (&se->pre, &se->post, se->loop, - info, mold_type, false, true, false); + info, mold_type, false, true, false, + &expr->where); /* Cast the pointer to the result. */ tmp = gfc_conv_descriptor_data_get (info->descriptor); diff --git a/gcc/fortran/trans-io.c b/gcc/fortran/trans-io.c index f210169abe0..7f98e5c7c71 100644 --- a/gcc/fortran/trans-io.c +++ b/gcc/fortran/trans-io.c @@ -1900,7 +1900,7 @@ transfer_expr (gfc_se * se, gfc_typespec * ts, tree addr_expr, gfc_code * code); recursive. */ static tree -transfer_array_component (tree expr, gfc_component * cm) +transfer_array_component (tree expr, gfc_component * cm, locus * where) { tree tmp; stmtblock_t body; @@ -1944,7 +1944,7 @@ transfer_array_component (tree expr, gfc_component * cm) gfc_init_loopinfo (&loop); gfc_add_ss_to_loop (&loop, ss); gfc_conv_ss_startstride (&loop); - gfc_conv_loop_setup (&loop); + gfc_conv_loop_setup (&loop, where); gfc_mark_ss_chain_used (ss, 1); gfc_start_scalarized_body (&loop, &body); @@ -2089,7 +2089,7 @@ transfer_expr (gfc_se * se, gfc_typespec * ts, tree addr_expr, gfc_code * code) if (c->dimension) { - tmp = transfer_array_component (tmp, c); + tmp = transfer_array_component (tmp, c, & code->loc); gfc_add_expr_to_block (&se->pre, tmp); } else @@ -2213,7 +2213,7 @@ gfc_trans_transfer (gfc_code * code) /* Initialize the loop. */ gfc_conv_ss_startstride (&loop); - gfc_conv_loop_setup (&loop); + gfc_conv_loop_setup (&loop, &code->expr->where); /* The main loop body. */ gfc_mark_ss_chain_used (ss, 1); diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c index 6afac5d3734..e19695fdade 100644 --- a/gcc/fortran/trans-stmt.c +++ b/gcc/fortran/trans-stmt.c @@ -269,7 +269,8 @@ gfc_conv_elemental_dependencies (gfc_se * se, gfc_se * loopse, tmp = gfc_typenode_for_spec (&e->ts); tmp = gfc_trans_create_temp_array (&se->pre, &se->post, &tmp_loop, info, tmp, - false, true, false); + false, true, false, + & arg->expr->where); gfc_add_modify_expr (&se->pre, size, tmp); tmp = fold_convert (pvoid_type_node, info->data); gfc_add_modify_expr (&se->pre, data, tmp); @@ -375,7 +376,7 @@ gfc_trans_call (gfc_code * code, bool dependency_check) gfc_add_ss_to_loop (&loop, ss); gfc_conv_ss_startstride (&loop); - gfc_conv_loop_setup (&loop); + gfc_conv_loop_setup (&loop, &code->expr->where); gfc_mark_ss_chain_used (ss, 1); /* Convert the arguments, checking for dependencies. */ @@ -1977,7 +1978,7 @@ generate_loop_for_temp_to_lhs (gfc_expr *expr, tree tmp1, tree count3, /* Calculate the bounds of the scalarization. */ gfc_conv_ss_startstride (&loop1); /* Setup the scalarizing loops. */ - gfc_conv_loop_setup (&loop1); + gfc_conv_loop_setup (&loop1, &expr->where); gfc_mark_ss_chain_used (lss, 1); @@ -2075,7 +2076,7 @@ generate_loop_for_rhs_to_temp (gfc_expr *expr2, tree tmp1, tree count3, gfc_add_ss_to_loop (&loop, rss); gfc_conv_ss_startstride (&loop); - gfc_conv_loop_setup (&loop); + gfc_conv_loop_setup (&loop, &expr2->where); gfc_mark_ss_chain_used (rss, 1); /* Start the loop body. */ @@ -2197,7 +2198,7 @@ compute_inner_temp_size (gfc_expr *expr1, gfc_expr *expr2, flag_bounds_check = 0; gfc_conv_ss_startstride (&loop); flag_bounds_check = save_flag; - gfc_conv_loop_setup (&loop); + gfc_conv_loop_setup (&loop, &expr2->where); /* Figure out how many elements we need. */ for (i = 0; i < loop.dimen; i++) @@ -2538,7 +2539,7 @@ gfc_trans_pointer_assign_need_temp (gfc_expr * expr1, gfc_expr * expr2, /* Setup the scalarizing loops and bounds. */ gfc_conv_ss_startstride (&loop); - gfc_conv_loop_setup (&loop); + gfc_conv_loop_setup (&loop, &expr2->where); info = &rss->data.info; desc = info->descriptor; @@ -3019,7 +3020,7 @@ gfc_evaluate_where_mask (gfc_expr * me, forall_info * nested_forall_info, gfc_add_ss_to_loop (&loop, rss); gfc_conv_ss_startstride (&loop); - gfc_conv_loop_setup (&loop); + gfc_conv_loop_setup (&loop, &me->where); gfc_mark_ss_chain_used (rss, 1); /* Start the loop body. */ @@ -3186,7 +3187,7 @@ gfc_trans_where_assign (gfc_expr *expr1, gfc_expr *expr2, gfc_conv_resolve_dependencies (&loop, lss_section, rss); /* Setup the scalarizing loops. */ - gfc_conv_loop_setup (&loop); + gfc_conv_loop_setup (&loop, &expr2->where); /* Setup the gfc_se structures. */ gfc_copy_loopinfo_to_se (&lse, &loop); @@ -3634,7 +3635,7 @@ gfc_trans_where_3 (gfc_code * cblock, gfc_code * eblock) } gfc_conv_ss_startstride (&loop); - gfc_conv_loop_setup (&loop); + gfc_conv_loop_setup (&loop, &tdst->where); gfc_mark_ss_chain_used (css, 1); gfc_mark_ss_chain_used (tdss, 1); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f4d271c3e17..5fb8ff609c6 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2008-07-24 Thomas Koenig + + PR fortran/29952 + * gfortran.dg/array_temporaries_1.f90: New test case. + 2008-07-23 Ian Lance Taylor * gcc.target/i386/20080723-1.c: New test. diff --git a/gcc/testsuite/gfortran.dg/array_temporaries_1.f90 b/gcc/testsuite/gfortran.dg/array_temporaries_1.f90 new file mode 100644 index 00000000000..64fc59046f4 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/array_temporaries_1.f90 @@ -0,0 +1,19 @@ +! { dg-do compile } +! { dg-options "-Warray-temporaries" } + +subroutine bar(a) + real, dimension(2) :: a +end + +program main + integer, parameter :: n=3 + integer :: i + real, dimension(n) :: a, b + + a = 0.2 + i = 2 + a(i:i+1) = a(1:2) ! { dg-warning "Creating array temporary" } + a = cshift(a,1) ! { dg-warning "Creating array temporary" } + b = cshift(a,1) + call bar(a(1:3:2)) ! { dg-warning "Creating array temporary" } +end program main -- 2.30.2