Bug 52078 - Bogus may be used uninitialized warning
Summary: Bogus may be used uninitialized warning
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks: Wuninitialized
  Show dependency treegraph
 
Reported: 2012-02-01 02:37 UTC by Ryan Mansfield
Modified: 2012-02-07 17:57 UTC (History)
1 user (show)

See Also:
Host: x86_64-linux-gnu
Target: x86_64-linux-gnu
Build: x86_64-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2012-02-01 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ryan Mansfield 2012-02-01 02:37:52 UTC
gcc version 4.7.0 20120201 (experimental) [trunk revision 183790] (GCC) 

Testcase:

#include <string.h>

int
foo (char *nname, char *oname)
{
  int cmp;

  while (nname != oname && (cmp = strcmp (nname, oname)) < 0)
    {
      break;
    }
  if (nname == oname || cmp == 0)
    {
      return 1;
    }
  else
    {
      return 0;
    }
}


$ ./xgcc -B. -O2 -Wall ~/init.c -c 
/home/ryan/init.c: In function 'foo':
/home/ryan/init.c:12:29: warning: 'cmp' may be used uninitialized in this function [-Wmaybe-uninitialized]

Since both && and || operators guarantee left-to-right evaluation, in the case where nname == oname, strcmp is never called but in the (name == oname || cmp == 0) expression, nname == oname and the second operand is not evaluated so cmp is never used uninitialized.
Comment 1 Manuel López-Ibáñez 2012-02-01 08:17:27 UTC
I haven't followed development for a while, but I don't think GCC uninit analysis is powerful enough to detect this or even simpler cases like PR36550 and PR20968.
Comment 2 Richard Biener 2012-02-01 09:28:49 UTC
Yeah, it's simply too confusing code for GCCs static analysis.  Thus the "may be used uninitialized".