public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Fix reload1.c warning for some targets
@ 2015-08-05 14:18 Richard Sandiford
  2015-08-05 17:01 ` Jeff Law
  2015-08-12 17:17 ` Jeff Law
  0 siblings, 2 replies; 11+ messages in thread
From: Richard Sandiford @ 2015-08-05 14:18 UTC (permalink / raw)
  To: gcc-patches

Building some targets results in a warning about orig_dup[i] potentially
being used uninitialised.  I think the warning is fair, since it isn't
obvious that the reog_data-based loop bound remains unchanged between:

  for (i = 0; i < recog_data.n_dups; i++)
    orig_dup[i] = *recog_data.dup_loc[i];

and:

  for (i = 0; i < recog_data.n_dups; i++)
    *recog_data.dup_loc[i] = orig_dup[i];

Tested on x86_64-linux-gnu.  OK to install?

Thanks,
Richard

gcc/
	* reload1.c (elimination_costs_in_insn): Make it obvious to the
	compiler that the n_dups and n_operands loop bounds are invariant.

diff --git a/gcc/reload1.c b/gcc/reload1.c
index ce06e06..ad243e3 100644
--- a/gcc/reload1.c
+++ b/gcc/reload1.c
@@ -3708,10 +3708,12 @@ elimination_costs_in_insn (rtx_insn *insn)
   /* Eliminate all eliminable registers occurring in operands that
      can be handled by reload.  */
   extract_insn (insn);
-  for (i = 0; i < recog_data.n_dups; i++)
+  int n_dups = recog_data.n_dups;
+  for (i = 0; i < n_dups; i++)
     orig_dup[i] = *recog_data.dup_loc[i];
 
-  for (i = 0; i < recog_data.n_operands; i++)
+  int n_operands = recog_data.n_operands;
+  for (i = 0; i < n_operands; i++)
     {
       orig_operand[i] = recog_data.operand[i];
 
@@ -3756,7 +3758,7 @@ elimination_costs_in_insn (rtx_insn *insn)
 	}
     }
 
-  for (i = 0; i < recog_data.n_dups; i++)
+  for (i = 0; i < n_dups; i++)
     *recog_data.dup_loc[i]
       = *recog_data.operand_loc[(int) recog_data.dup_num[i]];
 
@@ -3764,9 +3766,9 @@ elimination_costs_in_insn (rtx_insn *insn)
   check_eliminable_occurrences (old_body);
 
   /* Restore the old body.  */
-  for (i = 0; i < recog_data.n_operands; i++)
+  for (i = 0; i < n_operands; i++)
     *recog_data.operand_loc[i] = orig_operand[i];
-  for (i = 0; i < recog_data.n_dups; i++)
+  for (i = 0; i < n_dups; i++)
     *recog_data.dup_loc[i] = orig_dup[i];
 
   /* Update all elimination pairs to reflect the status after the current

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2015-09-10 19:19 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-05 14:18 Fix reload1.c warning for some targets Richard Sandiford
2015-08-05 17:01 ` Jeff Law
2015-08-05 17:33   ` Richard Sandiford
2015-08-11 20:05     ` Jeff Law
2015-08-12 17:17 ` Jeff Law
2015-08-13 20:33   ` Richard Sandiford
2015-08-13 21:08     ` Jeff Law
2015-08-24 11:05     ` Rainer Orth
2015-09-03  8:50       ` Richard Sandiford
2015-09-04 20:16         ` Jeff Law
2015-09-10 19:33           ` Richard Sandiford

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).