public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/100579] New: [coroutines] Poor codegen using an optional-like type with co_await
@ 2021-05-13  3:24 rs2740 at gmail dot com
  2021-10-01 20:09 ` [Bug c++/100579] " iains at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: rs2740 at gmail dot com @ 2021-05-13  3:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100579

            Bug ID: 100579
           Summary: [coroutines] Poor codegen using an optional-like type
                    with co_await
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rs2740 at gmail dot com
  Target Milestone: ---

#ifdef __clang__
#include <experimental/coroutine>
namespace stdx = std::experimental;
#else
#include <coroutine>
namespace stdx = std;
#endif
struct O {
 ~O() {}
 struct promise_type {
     O get_return_object() { return O{this};}
     stdx::suspend_never initial_suspend() { return {}; }
     stdx::suspend_never final_suspend() noexcept { return {}; }
     void return_void(){ value->b = true; }
     void unhandled_exception(){ throw; }

     auto await_transform(O o) {
         struct A {
             bool await_ready() {
                 return o_.b;
             }
             void await_resume() {}
             void await_suspend(stdx::coroutine_handle<> h){
                 h.destroy();
             }
             O o_;
         };
         return A{o};
     }
     O* value;
 };

 explicit O(promise_type* p){ p->value = this; }
 explicit O(bool b) : b(b) {}

 bool b = false;
};

O g();

O f() { co_await g();  co_return; }

This is basically a reduced version of
https://github.com/facebook/folly/blob/99f856ae2009a80b157b5121e44b1f70f61bd7c9/folly/Optional.h#L613-L678

GCC does not appear to be able to optimize away the coroutine frame allocation,
while Clang does: https://gcc.godbolt.org/z/7981o81ne

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-10-01 20:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-13  3:24 [Bug c++/100579] New: [coroutines] Poor codegen using an optional-like type with co_await rs2740 at gmail dot com
2021-10-01 20:09 ` [Bug c++/100579] " iains 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).