Bug 59225 - missing maybe uninitialized warning following single if
Summary: missing maybe uninitialized warning following single if
Status: RESOLVED DUPLICATE of bug 18501
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.9.0
: P3 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-11-21 03:12 UTC by Vincent Lefèvre
Modified: 2013-11-21 03:43 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vincent Lefèvre 2013-11-21 03:12:28 UTC
With:
* gcc-4.8 (Debian 4.8.2-5) 4.8.2
* gcc (Debian 20131021-1) 4.9.0 20131021 (experimental) [trunk revision 203899]

xvii:~> cat tst1.c
int foo (int x)
{
  int y;
  if (x == 0)
    y = 1;
  return y;
}

"gcc-snapshot -O2 -Wuninitialized -c tst1.c" doesn't emit any warning.

If I change the code to:

xvii:~> cat tst2.c
int foo (int x)
{
  int y;
  if (x == 0)
    y = 1;
  else if (x == 1)
    y = 2;
  return y;
}

I get the following warning as expected:

tst2.c:8:3: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
   return y;
   ^
Comment 1 Manuel López-Ibáñez 2013-11-21 03:43:53 UTC
CCP assumes y == 1 in the first testcase, this is PR18501

In the second testcase, y may be either 1 or 2, so CCP does not kick-in, and  nothing removes the undefined operand of the PHI node:

  # RANGE [1, 2] NONZERO 0x00000000000000003   
  # y_1 = PHI <[test2.c : 5:7] 1(6), y_3(D)(4), [test2.c : 7:7] 2(7)>
  [test2.c : 8:3] # VUSE <.MEM_4(D)>
  return y_1;

so we can warn.

*** This bug has been marked as a duplicate of bug 18501 ***