User account creation filtered due to spam.

Bug 52078

Summary: Bogus may be used uninitialized warning
Product: gcc Reporter: Ryan Mansfield <rmansfield>
Component: tree-optimizationAssignee: Not yet assigned to anyone <unassigned>
Status: NEW ---    
Severity: normal CC: manu
Priority: P3 Keywords: diagnostic
Version: 4.7.0   
Target Milestone: ---   
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
Bug Depends on:    
Bug Blocks: 24639    

Description Ryan Mansfield 2012-02-01 02:37:52 UTC
gcc version 4.7.0 20120201 (experimental) [trunk revision 183790] (GCC) 


#include <string.h>

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

  while (nname != oname && (cmp = strcmp (nname, oname)) < 0)
  if (nname == oname || cmp == 0)
      return 1;
      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".