Bug 55873 - Missed trivial uninitialized use warning
Summary: Missed trivial uninitialized use warning
Status: RESOLVED WONTFIX
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2013-01-04 11:37 UTC by Steven Bosscher
Modified: 2013-01-05 12:15 UTC (History)
1 user (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.