From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 38B053858012; Tue, 6 Apr 2021 20:59:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 38B053858012 From: "vincent-gcc at vinc17 dot net" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/99944] New: incorrect maybe-uninitialized warning on variable defined as an array Date: Tue, 06 Apr 2021 20:59:47 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vincent-gcc at vinc17 dot net X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Apr 2021 20:59:47 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99944 Bug ID: 99944 Summary: incorrect maybe-uninitialized warning on variable defined as an array Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: vincent-gcc at vinc17 dot net Target Milestone: --- Consider the following testcase derived from the initial testcase of PR85777 and its cleaned-up testcase (which is actually a bit different since an enum was replaced by an int, and it matters here). int d; int h(void); void e1(void) { int f[2]; int g =3D 0; if (d) g++; if (d =3D=3D 1) f[g++] =3D 2; (void) (f[0] || (g && h())); } void e2(void) { enum { a } f[2]; int g =3D 0; if (d) g++; if (d =3D=3D 1) f[g++] =3D a; (void) (f[0] || (g && h())); } With a GCC snapshot built a few hour ago from the master branch: cventin% gcc --version gcc (GCC) 11.0.1 20210406 (experimental) [...] cventin% gcc -Werror=3Dmaybe-uninitialized -O2 -c file.c file.c: In function =E2=80=98e1=E2=80=99: file.c:11:3: error: =E2=80=98f[0]=E2=80=99 may be used uninitialized [-Werror=3Dmaybe-uninitialized] 11 | (void) (f[0] || (g && h())); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ file.c: In function =E2=80=98e2=E2=80=99: file.c:21:3: error: =E2=80=98*(unsigned int *)(&f[0])=E2=80=99 may be used = uninitialized [-Werror=3Dmaybe-uninitialized] 21 | (void) (f[0] || (g && h())); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: some warnings being treated as errors The error for e1 is correct, but not the one for e2 (for e2, previous GCC versions were outputting =E2=80=98f=E2=80=99 instead of =E2=80=98*(unsigned= int *)(&f[0])=E2=80=99, but this is about the same thing). cventin% gcc -Werror=3Dmaybe-uninitialized -O2 -c file.c -fsanitize=3Dundef= ined file.c: In function =E2=80=98e1=E2=80=99: file.c:11:12: error: =E2=80=98f=E2=80=99 may be used uninitialized [-Werror=3Dmaybe-uninitialized] 11 | (void) (f[0] || (g && h())); | ~^~~ file.c:5:7: note: =E2=80=98f=E2=80=99 declared here 5 | int f[2]; | ^ file.c: In function =E2=80=98e2=E2=80=99: file.c:21:12: error: =E2=80=98f=E2=80=99 may be used uninitialized [-Werror=3Dmaybe-uninitialized] 21 | (void) (f[0] || (g && h())); | ~^~~ file.c:15:14: note: =E2=80=98f=E2=80=99 declared here 15 | enum { a } f[2]; | ^ cc1: some warnings being treated as errors Here, with the option -fsanitize=3Dundefined added, both errors are incorre= ct.=