Bug 55873

Summary: Missed trivial uninitialized use warning
Product: gcc Reporter: Steven Bosscher <steven>
Component: middle-endAssignee: Not yet assigned to anyone <unassigned>
Severity: normal CC: manu
Priority: P3 Keywords: diagnostic
Version: 4.8.0   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: 4.6.3, 4.8.0 Last reconfirmed:

Description Steven Bosscher 2013-01-04 11:37:58 UTC
extern int foo (int);
int foo (int c)
  int res;
  if (c)
    res = 0;
  return res;

res may be used uninitialized if c==0, but the function is "optimized" to
"return 0" before the uninit1 warning pass runs.
Comment 1 Richard Biener 2013-01-04 11:46:06 UTC
It's conditionally uninitialized and thus only warned in late uninit pass.
This is a known issue of optimistic constant propagation.

Duplicate of PRxyz.  Never going to be fixed.
Comment 2 Manuel López-Ibáñez 2013-01-05 12:10:56 UTC
PR18501, the most frequently reported Wuninitialized bug.
Comment 3 Manuel López-Ibáñez 2013-01-05 12:15:35 UTC
PR18501, the most frequently reported Wuninitialized bug.

Of course, it is possible to fix it. Clang does warn:

pr18501.c:5:7: warning: variable 'res' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
  if (c)
pr18501.c:7:10: note: uninitialized use occurs here
  return res;
pr18501.c:5:3: note: remove the 'if' if its condition is always true
  if (c)
pr18501.c:4:10: note: initialize the variable 'res' to silence this warning
  int res;
          = 0
1 warning generated.

It is just that it probably needs some serious amount of work.