From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id F2F5D3858D1E; Wed, 16 Mar 2022 15:56:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F2F5D3858D1E From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/104958] New: missing -Wdangling-pointer leaking local address through struct member Date: Wed, 16 Mar 2022 15:56:33 +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: Wed, 16 Mar 2022 15:56:34 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104958 Bug ID: 104958 Summary: missing -Wdangling-pointer leaking local address through struct member 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: --- As discussed in https://gcc.gnu.org/pipermail/gcc-patches/2022-February/590230.html both functions in the following test case leak the address of the local variable= to their caller and should trigger a -Wdangling pointer but only one of them d= oes. The patch submitted to implement this missing functionality was deferred u= ntil GCC 13: https://gcc.gnu.org/pipermail/gcc-patches/attachments/20220210/2641dce0/att= achment-0003.bin $ cat x.c && gcc -S -Wall x.c struct S { void *p; }; void f (struct S *p) { int j; p->p =3D &j; // -Wdangling-pointer } struct S g (void) { int i; struct S s =3D { &i }; // missing -Wdangling-pointer return s; } x.c: In function =E2=80=98f=E2=80=99: x.c:6:8: warning: storing the address of local variable =E2=80=98j=E2=80=99= in =E2=80=98*p.p=E2=80=99 [-Wdangling-pointer=3D] 6 | p->p =3D &j; // -Wdangling-pointer | ~~~~~^~~~ x.c:5:7: note: =E2=80=98j=E2=80=99 declared here 5 | int j; | ^ x.c:5:7: note: =E2=80=98p=E2=80=99 declared here=