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
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ 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] 5+ 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
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ 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] 5+ 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
  3 siblings, 0 replies; 5+ 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] 5+ 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
  3 siblings, 0 replies; 5+ 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] 5+ 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
  3 siblings, 0 replies; 5+ 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] 5+ messages in thread

end of thread, other threads:[~2024-02-05 14:23 UTC | newest]

Thread overview: 5+ 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

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).