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

            Bug ID: 128587
           Summary: Errant warning -Wmaybe-uninitialized at -O3 - but
                    shows proper initialization
           Product: gcc
           Version: 16.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: drankinatty at gmail dot com
  Target Milestone: ---

This bug is filed as a separate bug per the request in
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114592 (a similar bug affecting
C++ instead of C)

I see an errant warning in C gcc (SUSE Linux) 16.2.1 20260929 with basic
plane-old arrays and -O3, but frustratingly random. There is no warning at -O2.
The warning is actually a bit ironic, because it does a great job showing the
poa is initialized while warning it may not be with:

$ gcc -Wall -Wextra -pedantic -Wshadow -march=native -std=c23 -O3 -o ptrarrneur
ptrarrneur.c layers.c -lm
In function ‘err_total’,
    inlined from ‘main’ at ptrarrneur.c:229:12:
ptrarrneur.c:130:19: warning: ‘target’ may be used uninitialized
[-Wmaybe-uninitialized]
  130 |     l->error[i] = erf (target[i], l->output[i], l->nneur);
      |                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ptrarrneur.c: In function ‘main’:
ptrarrneur.c:199:9: note: ‘target’ declared here
  199 |   float target[] = { .05, .95 },
      |         ^~~~~~

The function and initialization involved:

float err_total (layer_t *l, float *target, float (*erf)(float, float,
unsigned))
{
  float etotal = 0.;

  for (unsigned i = 0; i < l->nneur; i++) {
    l->error[i] = erf (target[i], l->output[i], l->nneur);
    etotal += l->error[i];
  }

  return etotal;
}


int main (void) {

  float target[] = { .05, .95 },
        etotal = 0.;

  /* compute total error */
  etotal = err_total (&l[NLAYERS - 1], target, err_mse);

}

This likely is a related issue in optimization as in the cited C++ bug.

Reply via email to