From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id CAAD63858C83; Wed, 11 Jan 2023 21:03:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CAAD63858C83 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673471020; bh=aQeLQrteBrqWenPc/Vc7ZtPYJjnDbFgf1SK9/31UNKc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=MIYee6CPgRaGQX7owFaE2uIvrV5zXjZa6fqSUnP2/Fr9HY4U4tnECmZCV8NL1jPDh eB/WhxgfYEbRdWCB7jvlWOqdkFRrUw6FOXdsTJk3GCE48KkKXizqLNclc09eoKOCIe chrx4VNuEUMTQd163xiMxd+RwdUFxAMWY9x77B5E= From: "guilherme.janczak at yandex dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/107838] spurious "may be used uninitialized" warning on variable initialized at the first iteration of a loop Date: Wed, 11 Jan 2023 21:03:40 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: guilherme.janczak at yandex dot com X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: rguenth at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107838 Guilherme Janczak changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |guilherme.janczak at yande= x dot co | |m --- Comment #3 from Guilherme Janczak = --- I just ran into the same bug with the following code: /* rand32: return 32 bits of randomness */ static unsigned long rand32(void) { int rand(void); unsigned long rval; /* * There is modulo bias in this example if RAND_MAX isn't a power o= f 2 * minus 1, but that is irrelevant for the bug report. * * C only guarantees RAND_MAX is at least 32767, that is, 15 bits. */ rval =3D rand() & 0x7FFF; rval <<=3D 15; rval |=3D rand() & 0x7FFF; rval <<=3D 2; rval |=3D rand() & 0x03; return rval; } /* rand_hex: fill a buffer with random hex digits */ void rand_hex(unsigned char *buf, int len) { const char *hex =3D "0123456789ABCDEF"; int i; unsigned long r; for (i =3D 0; i < len; i++) { /* If we don't have any random bits in r, get some more. */ if (i % 8 =3D=3D 0) r =3D rand32(); /* Use 4 bits from the 32-bit integer at a time. */ buf[i] =3D hex[r & 0x0F]; r >>=3D 4; } } $ gcc -O -c -Wmaybe-uninitialized test.c test.c: In function 'rand_hex': test.c:37:19: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized] 37 | r >>=3D 4; | ~~^~~~~ Notice how the 1st usage of r doesn't cause the warning, but the 2nd one do= es. I haven't tested GCC 13.0.0, I get this with the GCC 12.2.1 from Alpine Lin= ux and 11.2.0 from OpenBSD, here's their respective `gcc -v` outputs: gcc version 12.2.1 20220924 (Alpine 12.2.1_git20220924-r4) gcc version 11.2.0 (GCC)=