https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95555

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
The reload_cse_simplify_operands() function allocates three arrays but resets
only two:

  alternative_reject = XALLOCAVEC (int, recog_data.n_alternatives);
  alternative_nregs = XALLOCAVEC (int, recog_data.n_alternatives);
  alternative_order = XALLOCAVEC (int, recog_data.n_alternatives);
  memset (alternative_reject, 0, recog_data.n_alternatives * sizeof (int));
  memset (alternative_nregs, 0, recog_data.n_alternatives * sizeof (int));

It then assigns to the alternative_order array in the loop below, but only
conditionally:

  /* Record all alternatives which are better or equal to the currently
     matching one in the alternative_order array.  */
  for (i = j = 0; i < recog_data.n_alternatives; i++)
    if (alternative_reject[i] <= alternative_reject[which_alternative])
      alternative_order[j++] = i;
  recog_data.n_alternatives = j;

Finally, it unconditionally reads the first element:

  /* Substitute the operands as determined by op_alt_regno for the best
     alternative.  */
  j = alternative_order[0];

I don't know this part of the compiler to tell if the first element is
guaranteed to be stored into by the loop, and it seems that GCC can't figure it
out either, so it issues the warning.  That's expected.  If the element is
guaranteed to be set by the loop then storing a zero into it before the loop
should be safe and avoid the warning.  If it isn't, someone familiar with the
code should look into what the right initial value should be.  The affected
code hasn't changed since 2003 but Jakub and Richard Sandiford have made
changes to the function since then so they might be able to help.

In the meantime, I would suggest zeroing out the first element to see if that
helps.  Bill, can you give it a try?

Reply via email to