public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "StevenSun2021 at hotmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/109283] Destructor of co_yield conditional argument called twice Date: Wed, 29 Mar 2023 07:11:07 +0000 [thread overview] Message-ID: <bug-109283-4-ZZ3iOFExWq@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-109283-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109283 Steven Sun <StevenSun2021 at hotmail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |StevenSun2021 at hotmail dot com --- Comment #1 from Steven Sun <StevenSun2021 at hotmail dot com> --- It is indeed a bug. I currently only investigated into the gcc-12, it generates something for ``` struct S{ /**/ }; bool w; co_yield w ? S{"a"} : S{"b"}; ``` pseudo-code for the generated gimple: ``` char __res[sizeof(S)]; char __a[sizeof(S)]; char __b[sizeof(S)]; new (__a) S("a"); new (__b) S("b"); if (w) memcpy(__res, __a, sizeof(S)); else memcpy(__res, __b, sizeof(S)); /* ... */ __b->~S(); __a->~S(); __c->~S(); ``` So, clearly there is at least 3 bugs here: i. `__res` is never constructed. ii. only one of the `__a` and `__b` should be constructed, not both. iii. the assignment is not corrected (it uses `gimple_assign` for value copy). If the ii is correctly implemented, iii will not happen. Though, the code will work fine on all trivial types. The correct code should be ``` char __res[sizeof(S)]; if (w) new (__res) S("a"); else new (__res) S("b"); /* ... */ __res->~S(); ```
next prev parent reply other threads:[~2023-03-29 7:11 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-03-26 2:16 [Bug c++/109283] New: " ncm at cantrip dot org 2023-03-29 7:11 ` StevenSun2021 at hotmail dot com [this message] 2023-03-29 15:45 ` [Bug c++/109283] " ncm at cantrip dot org 2023-05-08 14:23 ` ncm at cantrip dot org 2024-02-05 14:23 ` redi at gcc dot gnu.org 2024-05-20 16:10 ` accelerator0099 at gmail dot com 2024-05-26 4:55 ` accelerator0099 at gmail dot com
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-109283-4-ZZ3iOFExWq@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).