https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107838

            Bug ID: 107838
           Summary: spurious "may be used uninitialized" warning on
                    variable initialized at the first iteration of a loop
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vincent-gcc at vinc17 dot net
  Target Milestone: ---

Consider

int f(void);
void g(int *t)
{
  int i, v;
  for (i = 0; i < 9; i++)
    {
      if (i == 0)
        v = f();
      if (v + t[i])
        f();
    }
}

$ gcc-test -O -Wmaybe-uninitialized -c tst3.c
tst3.c: In function ‘g’:
tst3.c:9:13: warning: ‘v’ may be used uninitialized [-Wmaybe-uninitialized]
    9 |       if (v + t[i])
      |           ~~^~~~~~
tst3.c:4:10: note: ‘v’ was declared here
    4 |   int i, v;
      |          ^

The variable v is initialized at the first iteration (i == 0). Therefore the
warning is incorrect.

This occurs with GCC 4.8, 6.5.0, 8.4.0, 9.5.0, 12.2.0, and 13.0.0 20220906
(experimental) from the master branch. But there are no warnings with GCC 4.9,
5.5.0, 10.4.0 and 11.3.0.

Note to myself (to check once this bug is fixed): this testcase is derived from
tmd/binary32/hrcases.c (warning on variable b).

Reply via email to