From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2B4953858C83; Mon, 7 Feb 2022 23:49:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2B4953858C83 From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/104436] New: spurious -Wdangling-pointer assigning local address to a class passed by value Date: Mon, 07 Feb 2022 23:49:56 +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, 07 Feb 2022 23:49:56 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104436 Bug ID: 104436 Summary: spurious -Wdangling-pointer assigning local address to a class passed by value 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, reduced from https://bugzilla.redhat.com/show_bug.cgi?id=3D2051740, shows that -Wdangling-pointer can be made to trigger by assigning an object of a C++ c= lass with a user-defined copy ctor that stores a pointer to a local in a function that takes an argument of the class by value. GCC transforms the by-value argument of the function to a by-reference, which is one of the use cases t= he warning is designed to detect. $ cat rhbz2051740.C && gcc -O1 -S -Wall -fdump-tree-optimized=3D/dev/stdout rhbz2051740.C struct S { S () =3D default; S (const S &s): p (s.p) { } void *p; }; void foo (S s) { int a[3]; S t; t.p =3D a; s =3D t; } rhbz2051740.C: In function =E2=80=98void foo(S)=E2=80=99: rhbz2051740.C:13:5: warning: storing the address of local variable =E2=80= =98a=E2=80=99 in =E2=80=98*s.S::p=E2=80=99 [-Wdangling-pointer=3D] 13 | s =3D t; | ~~^~~ rhbz2051740.C:11:7: note: =E2=80=98a=E2=80=99 declared here 11 | int a[3]; | ^ rhbz2051740.C:11:7: note: =E2=80=98s=E2=80=99 declared here ;; Function foo (_Z3foo1S, funcdef_no=3D3, decl_uid=3D2396, cgraph_uid=3D4, symbol_order=3D3) void foo (struct S & s) { int a[3]; [local count: 1073741824]: s_2(D)->p =3D &a; a =3D{v} {CLOBBER}; return; }=