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

--- Comment #1 from Vincent Lefèvre <vincent-gcc at vinc17 dot net> ---
I've cleaned up the testcase:

int d;
int h(void);
void e(void)
{
  int f[2];
  int g = 0;
  if (d)
    g++;
  if (d == 1)
    f[g++] = 2;
  (void) (f[0] || (g && h()));
}

Now:

cventin% gcc-snapshot -Werror=uninitialized -Werror=maybe-uninitialized -O2 -c
file.c
file.c: In function 'e':
file.c:11:3: error: 'f[0]' may be used uninitialized in this function
[-Werror=maybe-uninitialized]
   (void) (f[0] || (g && h()));
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
cventin%

but

cventin% gcc-snapshot -Werror=uninitialized -Werror=maybe-uninitialized -O2 -c
file.c -fsanitize=undefined
cventin%

(no errors).

Note (this may be a separate issue): If I understand correctly, f[0] is
actually *always* used uninitialized in this function. Indeed, f[0] might be
initialized only via "f[g++] = 2;", thus only if d == 1. But in this case, it
is actually f[1] that is initialized.

Reply via email to