public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c++/109283] New: Destructor of co_yield conditional argument called twice @ 2023-03-26 2:16 ncm at cantrip dot org 2023-03-29 7:11 ` [Bug c++/109283] " StevenSun2021 at hotmail dot com ` (5 more replies) 0 siblings, 6 replies; 7+ messages in thread From: ncm at cantrip dot org @ 2023-03-26 2:16 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109283 Bug ID: 109283 Summary: Destructor of co_yield conditional argument called twice Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: ncm at cantrip dot org Target Milestone: --- Created attachment 54754 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54754&action=edit Reproducer Basically: co_yield a ? s : t; segfaults, if (a) co_yield s; else co_yield t; does not. The segfault traces to s/t's destructor being called twice. Full reproducer attached, relying on Casey Carter's generator implementation, pasted in. This may be related to 101367. Compiled with gcc-12.2, this program segfaults. Compiled with gcc-trunk or gcc-coroutines on Godbolt, identified as: g++ (Compiler-Explorer-Build-gcc-13ec81eb4c3b484ad636000fa8f6d925e15fb983-binutils-2.38) 13.0.1 20230325 (experimental) the compiler ICEs: <source>:513:1: internal compiler error: in flatten_await_stmt, at cp/coroutines.cc:2899 513 | } ^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/109283] Destructor of co_yield conditional argument called twice 2023-03-26 2:16 [Bug c++/109283] New: Destructor of co_yield conditional argument called twice ncm at cantrip dot org @ 2023-03-29 7:11 ` StevenSun2021 at hotmail dot com 2023-03-29 15:45 ` ncm at cantrip dot org ` (4 subsequent siblings) 5 siblings, 0 replies; 7+ messages in thread From: StevenSun2021 at hotmail dot com @ 2023-03-29 7:11 UTC (permalink / raw) To: gcc-bugs 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(); ``` ^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/109283] Destructor of co_yield conditional argument called twice 2023-03-26 2:16 [Bug c++/109283] New: Destructor of co_yield conditional argument called twice ncm at cantrip dot org 2023-03-29 7:11 ` [Bug c++/109283] " StevenSun2021 at hotmail dot com @ 2023-03-29 15:45 ` ncm at cantrip dot org 2023-05-08 14:23 ` ncm at cantrip dot org ` (3 subsequent siblings) 5 siblings, 0 replies; 7+ messages in thread From: ncm at cantrip dot org @ 2023-03-29 15:45 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109283 --- Comment #2 from ncm at cantrip dot org --- Betting this one is fixed by deleting code. ^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/109283] Destructor of co_yield conditional argument called twice 2023-03-26 2:16 [Bug c++/109283] New: Destructor of co_yield conditional argument called twice ncm at cantrip dot org 2023-03-29 7:11 ` [Bug c++/109283] " StevenSun2021 at hotmail dot com 2023-03-29 15:45 ` 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 ` (2 subsequent siblings) 5 siblings, 0 replies; 7+ messages in thread From: ncm at cantrip dot org @ 2023-05-08 14:23 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109283 --- Comment #3 from ncm at cantrip dot org --- Appears fixed in 13.1 Still ICEs in trunk, Compiler-Explorer-Build-gcc-70d038235cc91ef1ea4fce519e628cfb2d297bff-binutils-2.40) 14.0.0 20230508 (experimental): <source>: In function 'std::generator<std::__cxx11::basic_string<char> > source(int&, std::string)': <source>:513:1: internal compiler error: in flatten_await_stmt, at cp/coroutines.cc:2899 513 | } ^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/109283] Destructor of co_yield conditional argument called twice 2023-03-26 2:16 [Bug c++/109283] New: Destructor of co_yield conditional argument called twice ncm at cantrip dot org ` (2 preceding siblings ...) 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 5 siblings, 0 replies; 7+ messages in thread From: redi at gcc dot gnu.org @ 2024-02-05 14:23 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109283 Jonathan Wakely <redi at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed| |2024-02-05 Ever confirmed|0 |1 Status|UNCONFIRMED |NEW CC| |iains at gcc dot gnu.org --- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to ncm from comment #3) > Appears fixed in 13.1 It's likely that it's not fixed, it's just that the release branches do not have as many consistency checks and assertions enabled as trunk does. > > Still ICEs in trunk, > Compiler-Explorer-Build-gcc-70d038235cc91ef1ea4fce519e628cfb2d297bff- > binutils-2.40) 14.0.0 20230508 (experimental): > <source>: In function 'std::generator<std::__cxx11::basic_string<char> > > source(int&, std::string)': > <source>:513:1: internal compiler error: in flatten_await_stmt, at > cp/coroutines.cc:2899 > 513 | } Confirmed. ^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/109283] Destructor of co_yield conditional argument called twice 2023-03-26 2:16 [Bug c++/109283] New: Destructor of co_yield conditional argument called twice ncm at cantrip dot org ` (3 preceding siblings ...) 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 5 siblings, 0 replies; 7+ messages in thread From: accelerator0099 at gmail dot com @ 2024-05-20 16:10 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109283 accelerator0099 at gmail dot com changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |accelerator0099 at gmail dot com --- Comment #5 from accelerator0099 at gmail dot com --- (In reply to Jonathan Wakely from comment #4) > (In reply to ncm from comment #3) > > Appears fixed in 13.1 > > It's likely that it's not fixed, it's just that the release branches do not > have as many consistency checks and assertions enabled as trunk does. > > > > > Still ICEs in trunk, > > Compiler-Explorer-Build-gcc-70d038235cc91ef1ea4fce519e628cfb2d297bff- > > binutils-2.40) 14.0.0 20230508 (experimental): > > <source>: In function 'std::generator<std::__cxx11::basic_string<char> > > > source(int&, std::string)': > > <source>:513:1: internal compiler error: in flatten_await_stmt, at > > cp/coroutines.cc:2899 > > 513 | } > > Confirmed. Was that fixed in 14.1? I can compile with 14.1 and run with no error ^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/109283] Destructor of co_yield conditional argument called twice 2023-03-26 2:16 [Bug c++/109283] New: Destructor of co_yield conditional argument called twice ncm at cantrip dot org ` (4 preceding siblings ...) 2024-05-20 16:10 ` accelerator0099 at gmail dot com @ 2024-05-26 4:55 ` accelerator0099 at gmail dot com 5 siblings, 0 replies; 7+ messages in thread From: accelerator0099 at gmail dot com @ 2024-05-26 4:55 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109283 --- Comment #6 from accelerator0099 at gmail dot com --- Still ICEs in truck commit 28b508233a12c13295f960a2cb8a4864879acfb4 May 25 2024 version 15.0.0 Output: co_yield_bug.cc:197:31: error: redefinition of default argument for ‘class _Alloc’ 197 | template <range _Rng, class _Alloc = allocator<byte>> | ^~~~~ In file included from /build/gcc/include/c++/15.0.0/ranges:72, from co_yield_bug.cc:17: /build/gcc/include/c++/15.0.0/bits/elements_of.h:55:26: note: original definition appeared here 55 | template<range _Range, typename _Alloc = allocator<byte>> | ^~~~~~~~ co_yield_bug.cc:204:9: error: redefinition of ‘template<class _Rng, class _Alloc> std::ranges::elements_of(_Rng&&, _Alloc)-> elements_of<_Range&&, _Alloc>’ 204 | elements_of(_Rng&&, _Alloc = {}) -> elements_of<_Rng&&, _Alloc>; | ^~~~~~~~~~~ /build/gcc/include/c++/15.0.0/bits/elements_of.h:63:5: note: ‘template<class _Range, class _Alloc> std::ranges::elements_of(_Range&&, _Alloc)-> elements_of<_Range&&, _Alloc>’ previously declared here 63 | elements_of(_Range&&, _Alloc = _Alloc()) | ^~~~~~~~~~~ co_yield_bug.cc: In function ‘std::generator<std::__cxx11::basic_string<char> > source(int&, std::string)’: co_yield_bug.cc:513:1: internal compiler error: in flatten_await_stmt, at cp/coroutines.cc:2875 513 | } | ^ 0x76fd99 flatten_await_stmt /build/git/gcc/gcc/cp/coroutines.cc:2875 0xac4833 flatten_await_stmt /build/git/gcc/gcc/cp/coroutines.cc:2904 0xac67d0 maybe_promote_temps /build/git/gcc/gcc/cp/coroutines.cc:3087 0xac67d0 await_statement_walker /build/git/gcc/gcc/cp/coroutines.cc:3726 0x169330c walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*)) /build/git/gcc/gcc/tree.cc:11468 0xac74e1 await_statement_walker /build/git/gcc/gcc/cp/coroutines.cc:3546 0x169330c walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*)) /build/git/gcc/gcc/tree.cc:11468 0xac6528 await_statement_walker /build/git/gcc/gcc/cp/coroutines.cc:3397 0x169330c walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*)) /build/git/gcc/gcc/tree.cc:11468 0xac69d0 await_statement_walker /build/git/gcc/gcc/cp/coroutines.cc:3386 0x169330c walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*)) /build/git/gcc/gcc/tree.cc:11468 0xac69d0 await_statement_walker /build/git/gcc/gcc/cp/coroutines.cc:3386 0x169330c walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*)) /build/git/gcc/gcc/tree.cc:11468 0xac6528 await_statement_walker /build/git/gcc/gcc/cp/coroutines.cc:3397 0x169330c walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*)) /build/git/gcc/gcc/tree.cc:11468 0x1693464 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*)) /build/git/gcc/gcc/tree.cc:11702 0xac6528 await_statement_walker /build/git/gcc/gcc/cp/coroutines.cc:3397 0x169330c walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*)) /build/git/gcc/gcc/tree.cc:11468 0xac69d0 await_statement_walker /build/git/gcc/gcc/cp/coroutines.cc:3386 0x169330c walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*)) /build/git/gcc/gcc/tree.cc:11468 ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-05-26 4:55 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2023-03-26 2:16 [Bug c++/109283] New: Destructor of co_yield conditional argument called twice ncm at cantrip dot org 2023-03-29 7:11 ` [Bug c++/109283] " StevenSun2021 at hotmail dot com 2023-03-29 15:45 ` 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
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).