[patch, fortran] Add warning for creation of array temporaries

View: New views
5 Messages — Rating Filter:   Alert me  

[patch, fortran] Add warning for creation of array temporaries

by Thomas Koenig-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello world,

this patch adds a warning flag for the creation of array temporaries, as
a possible aid to optimization.  All calls to internal_pack are also
flagged.

This isn't exactly what PR 29952 is about, because this is compile- time
instead of run-time, but I thought it was close enough to mention the PR
int che ChangeLog anyway.

Regression-tested on i686-pc-linux-gnu.  Doc changes tested with "make
info" and "make dvi".

OK for trunk?

        Thomas

2008-07-23  Thomas Koenig  <tkoenig@...>

        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 recurrsive 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  Thomas Koenig  <tkoenig@...>

        PR fortran/29952
        * gfortran.dg/array_temporaries_1.f90: New test case.



[array_temporaries_2.diff]

Index: trans-array.c
===================================================================
--- trans-array.c (revision 138022)
+++ trans-array.c (working copy)
@@ -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
   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 (st
 
   /* 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 (gf
    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_loopinf
     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
    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 * loo
   /* 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 * loo
       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_loopi
    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 *
       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, g
       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, g
     {
       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;
Index: trans-expr.c
===================================================================
--- trans-expr.c (revision 138022)
+++ trans-expr.c (working copy)
@@ -2059,7 +2059,7 @@ gfc_conv_subref_array_arg (gfc_se * parm
   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 * parm
   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
      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, gf
   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
       /* 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);
Index: trans-array.h
===================================================================
--- trans-array.h (revision 138022)
+++ trans-array.h (working copy)
@@ -32,7 +32,8 @@ void gfc_set_loop_bounds_from_array_spec
 
 /* 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_lo
 /* 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.  */
Index: gfortran.h
===================================================================
--- gfortran.h (revision 138022)
+++ gfortran.h (working copy)
@@ -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;
Index: lang.opt
===================================================================
--- lang.opt (revision 138022)
+++ lang.opt (working copy)
@@ -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
Index: trans-stmt.c
===================================================================
--- trans-stmt.c (revision 138022)
+++ trans-stmt.c (working copy)
@@ -269,7 +269,8 @@ gfc_conv_elemental_dependencies (gfc_se
   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 de
       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
       /* 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
       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
       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_
       /* 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,
       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_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, gf
     }
 
   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);
Index: invoke.texi
===================================================================
--- invoke.texi (revision 138022)
+++ invoke.texi (working copy)
@@ -137,9 +137,9 @@ by type.  Explanations are in the follow
 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,
 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, to avoid
+such temporaties.
+
 @item -Wcharacter-truncation
 @opindex @code{Wcharacter-truncation}
 @cindex warnings, character truncation
Index: trans-io.c
===================================================================
--- trans-io.c (revision 138022)
+++ trans-io.c (working copy)
@@ -1900,7 +1900,7 @@ transfer_expr (gfc_se * se, gfc_typespec
    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
   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
 
           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);
Index: trans-intrinsic.c
===================================================================
--- trans-intrinsic.c (revision 138022)
+++ trans-intrinsic.c (working copy)
@@ -1731,7 +1731,7 @@ gfc_conv_intrinsic_anyall (gfc_se * se,
 
   /* 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, g
 
   /* 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, g
 
   /* 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 *
 
   /* 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 * s
 
   /* 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 * s
 
   /* 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_s
       && 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_s
      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);
Index: options.c
===================================================================
--- options.c (revision 138022)
+++ options.c (working copy)
@@ -69,6 +69,7 @@ gfc_init_options (unsigned int argc, con
   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 c
       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;


[array_temporaries_1.f90]

! { 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


Re: [patch, fortran] Add warning for creation of array temporaries

by Ralf Wildenhues :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Thomas,

a couple of nits:

* Thomas Koenig wrote on Wed, Jul 23, 2008 at 03:15:21PM CEST:

> * 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 recurrsive call of gfc_add_loop_ss_code and to call of

recursive

> gfc_trans_array_constructor.

> --- invoke.texi (revision 138022)
> +++ invoke.texi (working copy)

> @@ -698,6 +698,13 @@ given in a continued character constant,
>  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, to avoid

s/to/in order to/  ?

> +such temporaties.

temporaries

Cheers,
Ralf

Re: [patch, fortran] Add warning for creation of array temporaries

by Thomas Koenig-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, 2008-07-24 at 07:56 +0200, Ralf Wildenhues wrote:



> > to recurrsive call of gfc_add_loop_ss_code and to call of
>
> recursive

> > +Warn about array temporaries generated by the compiler.  The information
> > +generated by this warning is sometimes useful in optimization, to avoid
>
> s/to/in order to/  ?
>
> > +such temporaties.
>
> temporaries
>

All fixed.  Thanks!

OK otherwise?

        Thomas


Re: [patch, fortran] Add warning for creation of array temporaries

by Paul Richard Thomas :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thomas,

OK to commit.

Thanks

Paul

PS The example from Daniel,

SUBROUTINE sub(I)
 REAL, PARAMETER :: PI = 3.1415
 REAL, DIMENSION(:), POINTER   :: I
 I = 2.0 * PI**2 * I
END SUBROUTINE

produces a temporary because the scalarizer makes no attempt to
resolve pointers, for obvious reasons.  We could add a check that the
only pointer on the rhs is the same as that on the lhs, with no
dependencies, and that there are no targets in the rhs expression.
This should be posted on Bugzilla.



On Thu, Jul 24, 2008 at 8:32 AM, Thomas Koenig <tkoenig@...> wrote:

> On Thu, 2008-07-24 at 07:56 +0200, Ralf Wildenhues wrote:
>
>
>
>> >     to recurrsive call of gfc_add_loop_ss_code and to call of
>>
>> recursive
>
>> > +Warn about array temporaries generated by the compiler.  The information
>> > +generated by this warning is sometimes useful in optimization, to avoid
>>
>> s/to/in order to/  ?
>>
>> > +such temporaties.
>>
>> temporaries
>>
>
> All fixed.  Thanks!
>
> OK otherwise?
>
>        Thomas
>
>



--
The knack of flying is learning how to throw yourself at the ground and miss.
 --Hitchhikers Guide to the Galaxy

Re: [patch, fortran] Add warning for creation of array temporaries

by Thomas Koenig-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, 2008-07-24 at 09:57 +0200, Paul Richard Thomas wrote:
> Thomas,
>
> OK to commit.

Done, revision 138112.

Thanks!
        Thomas


LightInTheBox - Buy quality products at wholesale price