struct {int count;} *v1;
int c;
int k;

extern void baz(int);

static int bar(int *j)
{
    if (k == 4)
    {
        *j = 1;
        return 1;
    }
    return 0;
}

void foo(void)
{
    int i;

    if (!bar(&i))
    {
        if (!c)
            return;
        v1->count++;
    }
    if (!c)
    {
        baz(i);
    }
}

produces this warning when compiled with "-Wall -O2":

$ gcc-4.0.0-RC1 -Wall -O2 -c final.c
final.c: In function ‘foo’:
final.c:18: warning: ‘i’ may be used uninitialized in this function

GCC 3.4.3 and previous versions I tested did not generate this warning.

I believe this warning is improper because one of these two scenarios must be 
true:

1) k == 4, in which case i is initialized before it can be used
2) k != 4, in which case i is not used

Adding -fno-inline avoids the warning by preventing bar from being inlined into 
foo.

I was unable to reduce the test case further without making the warning
disappear.  In particular, removing the increment of v1->count makes the warning
disappear.

This is GCC 4.0.0 RC1:
$ gcc-4.0.0-RC1 -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.0.0-20050410/configure --program-suffix=-4.0.0-RC1
Thread model: posix
gcc version 4.0.0 20050410 (prerelease)

This warning still appears on mainline.

-- 
           Summary: [4.0/4.1 Regression] Spurious "may be used
                    uninitialized" warning
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: James dot Juran at baesystems dot com
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20968

Reply via email to