http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37997

--- Comment #2 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-01-19 
09:35:38 UTC ---
int foo (int i, int b)
{
  int mask;
  int result;
  if (b)
    mask = -1;
  else
    mask = 0;
  result = result & mask;
  return result;
}

actually works if you do not have result used uninitialized on the
path that sets mask to -1:

int foo (int i, int b, int result)
{
  int mask;
  if (b)
    mask = -1;
  else
    mask = 0;
  result = result & mask;
  return result;
}

is optimized to

<bb 2>:
  if (b_2(D) != 0)
    goto <bb 5>;
  else
    goto <bb 3>;

<bb 5>:
  pretmp.3_9 = result_5(D);
  goto <bb 4>;

<bb 3>:

<bb 4>:
  # mask_1 = PHI <-1(5), 0(3)>
  # prephitmp.4_10 = PHI <pretmp.3_9(5), 0(3)>
  result_6 = prephitmp.4_10;
  return result_6;

Likewise it works for

int foo (int i, int b)
{
  int mask;
  int result;
  if (b)
    mask = -1;
  else
    mask = 0;
  result = i + 1;
  result = result & mask;
  return result;
}

if you avoid the same error.  I don't think we want to consider
the uninitialized state of a variable to be available - we'd
insert "obvious" uninitialized uses and thus might expose them
to warnings.

Reply via email to