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

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It also seems to depend on array-to-pointer decay from float[nframes] to float*
across the function boundary, because if the loop using the size_t index is
moved into the same function as the array initialization, the analyzer doesn't
complain.

In any case, the value of size_t size should be assumed to positive.


Further reduced:

void sink(float);

void dsp_abs_max(float *buf, unsigned size) {
  sink(buf[size - 1]);
}
void export_audio(int nframes, float init, int count) {
  do {
    float tmp_l[nframes];
    for (int i = 0; i < nframes; i++)
      tmp_l[i] = init;
    dsp_abs_max(tmp_l, nframes);
  } while (--count);
}

$ gcc -fanalyzer -Werror=analyzer-use-of-uninitialized-value -c  a.c
a.c: In function ‘dsp_abs_max’:
a.c:4:3: error: use of uninitialized value ‘*buf_7(D) + _3’ [CWE-457]
[-Werror=analyzer-use-of-uninitialized-value]
    4 |   sink(buf[size - 1]);
      |   ^~~~~~~~~~~~~~~~~~~
  ‘export_audio’: events 1-5
    |
    |    6 | void export_audio(int nframes, float init, int count) {
    |      |      ^~~~~~~~~~~~
    |      |      |
    |      |      (1) entry to ‘export_audio’
    |    7 |   do {
    |    8 |     float tmp_l[nframes];
    |      |           ~~~~~
    |      |           |
    |      |           (2) region created on stack here
    |    9 |     for (int i = 0; i < nframes; i++)
    |      |                     ~~~~~~~~~~~
    |      |                       |
    |      |                       (3) following ‘false’ branch (when ‘i >=
nframes’)...
    |   10 |       tmp_l[i] = init;
    |   11 |     dsp_abs_max(tmp_l, nframes);
    |      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    |      |     |
    |      |     (4) ...to here
    |      |     (5) calling ‘dsp_abs_max’ from ‘export_audio’
    |
    +--> ‘dsp_abs_max’: events 6-7
           |
           |    3 | void dsp_abs_max(float *buf, unsigned size) {
           |      |      ^~~~~~~~~~~
           |      |      |
           |      |      (6) entry to ‘dsp_abs_max’
           |    4 |   sink(buf[size - 1]);
           |      |   ~~~~~~~~~~~~~~~~~~~
           |      |   |
           |      |   (7) use of uninitialized value ‘*buf_7(D) + _3’ here
           |
cc1: some warnings being treated as errors

Reply via email to