public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "msebor at gcc dot gnu.org" <gcc-bugzilla@gcc.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 [thread overview] Message-ID: <bug-104436-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104436 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=2051740, shows that -Wdangling-pointer can be made to trigger by assigning an object of a C++ class 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 the warning is designed to detect. $ cat rhbz2051740.C && gcc -O1 -S -Wall -fdump-tree-optimized=/dev/stdout rhbz2051740.C struct S { S () = default; S (const S &s): p (s.p) { } void *p; }; void foo (S s) { int a[3]; S t; t.p = a; s = t; } rhbz2051740.C: In function ‘void foo(S)’: rhbz2051740.C:13:5: warning: storing the address of local variable ‘a’ in ‘*s.S::p’ [-Wdangling-pointer=] 13 | s = t; | ~~^~~ rhbz2051740.C:11:7: note: ‘a’ declared here 11 | int a[3]; | ^ rhbz2051740.C:11:7: note: ‘s’ declared here ;; Function foo (_Z3foo1S, funcdef_no=3, decl_uid=2396, cgraph_uid=4, symbol_order=3) void foo (struct S & s) { int a[3]; <bb 2> [local count: 1073741824]: s_2(D)->p = &a; a ={v} {CLOBBER}; return; }
next reply other threads:[~2022-02-07 23:49 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-02-07 23:49 msebor at gcc dot gnu.org [this message] 2022-02-07 23:50 ` [Bug middle-end/104436] " msebor at gcc dot gnu.org 2022-02-08 0:22 ` msebor at gcc dot gnu.org 2022-02-08 9:08 ` rguenth at gcc dot gnu.org 2022-02-08 22:00 ` [Bug middle-end/104436] [12 Regression] " msebor at gcc dot gnu.org 2022-03-09 13:18 ` rguenth at gcc dot gnu.org 2022-03-15 0:27 ` cvs-commit at gcc dot gnu.org 2022-03-15 0:27 ` msebor at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-104436-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).