From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 285B03858403; Mon, 1 Nov 2021 23:50:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 285B03858403 From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/103036] New: incorrect #pragma GCC diagnostic suppression for macro expansion and -Wuninitialized Date: Mon, 01 Nov 2021 23:50:13 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: msebor at gcc dot gnu.org 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: Mon, 01 Nov 2021 23:50:13 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103036 Bug ID: 103036 Summary: incorrect #pragma GCC diagnostic suppression for macro expansion and -Wuninitialized Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- The test case below shows that suppressing -Wuninitialized by #pragma GCC diagnostic doesn't work the same as it does for other warnings (-Wrray-boun= ds in this instance, but most other warnings behave like it). This makes it difficult for users to control -Wuninitialized (and -Wmaybe-uninitialized), compounding their frustration when they run into one of its false positives. The reason for the difference is that tree-ssa-uninit.c calls linemap_resolve_location (line_table, location, LRK_SPELLING_LOCATION, NULL) before using location, which other warnings don't do. The call was introdu= ced in r186971 along with a test for its effect, gcc.dg/cpp/pragma-diagnostic-2= .c, with the goal to improve the macro expansion output printed by GCC with -ftrack-macro-expansion as well as its interaction with on #pragma GCC diagnostic. It seems to me that the change was ill thought out: I can thin= k of no reason why -Wunitialized should be treated differently from all other warnings. $ cat a.c && gcc -O2 -S -Wall -Werror a.c #define X(i) f (a[i]); int f (int); int g (void) { int a[3]; #pragma GCC diagnostic push #pragma GCC diagnostic warning "-Wuninitialized" return X (1); #pragma GCC diagnostic pop } int h (void) { int a[] =3D { 1, 2, 3 }; #pragma GCC diagnostic push #pragma GCC diagnostic warning "-Warray-bounds" return X (3); #pragma GCC diagnostic pop } a.c: In function =E2=80=98g=E2=80=99: a.c:1:14: error: =E2=80=98a=E2=80=99 is used uninitialized [-Werror=3Dunini= tialized] 1 | #define X(i) f (a[i]); | ^~~~~~~~ a.c:10:10: note: in expansion of macro =E2=80=98X=E2=80=99 10 | return X (1); | ^ a.c:7:7: note: =E2=80=98a=E2=80=99 declared here 7 | int a[3]; | ^ a.c: In function =E2=80=98h=E2=80=99: a.c:1:14: warning: array subscript 3 is above array bounds of =E2=80=98int[= 3]=E2=80=99 [-Warray-bounds] 1 | #define X(i) f (a[i]); | ^~~~~~~~ a.c:19:10: note: in expansion of macro =E2=80=98X=E2=80=99 19 | return X (3); | ^ a.c:16:7: note: while referencing =E2=80=98a=E2=80=99 16 | int a[] =3D { 1, 2, 3 }; | ^ cc1: all warnings being treated as errors=