libstdc++: Define noop coroutine details private and inline [PR 95917]

This moves the __noop_coro_frame type, the __noop_coro_fr global
variable, and the __dummy_resume_destroy function from namespace scope,
replacing them with private members of the specialization
coroutine_handle<noop_coroutine_promise>.

The function and variable are also declared inline, so that they
generate no code unless used.

libstdc++-v3/ChangeLog:

	PR libstdc++/95917
	* include/std/coroutine (__noop_coro_frame): Replace with
	noop_coroutine_handle::__frame.
	(__dummy_resume_destroy): Define inline in __frame.
	(__noop_coro_fr): Replace with noop_coroutine_handle::_S_fr
	and define as inline.
	* testsuite/18_support/coroutines/95917.cc: New test.
This commit is contained in:
Jonathan Wakely 2020-10-20 11:19:58 +01:00
parent 2c2278f300
commit 94fd05f1f7
2 changed files with 48 additions and 13 deletions

View File

@ -249,16 +249,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
};
void __dummy_resume_destroy() __attribute__((__weak__));
void __dummy_resume_destroy() {}
struct __noop_coro_frame
{
void (*__r)() = __dummy_resume_destroy;
void (*__d)() = __dummy_resume_destroy;
struct noop_coroutine_promise __p;
} __noop_coro_fr __attribute__((__weak__));
// 17.12.4.1 Class noop_coroutine_promise
/// [coroutine.promise.noop]
template <>
@ -284,7 +274,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// [coroutine.handle.noop.promise], promise access
noop_coroutine_promise& promise() const noexcept
{ return __noop_coro_fr.__p; }
{ return _S_fr.__p; }
// [coroutine.handle.noop.address], address
constexpr void* address() const noexcept { return _M_fr_ptr; }
@ -292,13 +282,27 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
private:
friend coroutine_handle noop_coroutine() noexcept;
coroutine_handle() = default;
struct __frame
{
static void __dummy_resume_destroy() { }
void* _M_fr_ptr = (void*) &__noop_coro_fr;
void (*__r)() = __dummy_resume_destroy;
void (*__d)() = __dummy_resume_destroy;
struct noop_coroutine_promise __p;
};
static __frame _S_fr;
explicit coroutine_handle() noexcept = default;
void* _M_fr_ptr = &_S_fr;
};
using noop_coroutine_handle = coroutine_handle<noop_coroutine_promise>;
inline noop_coroutine_handle::__frame
noop_coroutine_handle::_S_fr{};
inline noop_coroutine_handle noop_coroutine() noexcept
{
return noop_coroutine_handle();

View File

@ -0,0 +1,31 @@
// Copyright (C) 2020 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++2a -g0" }
// { dg-do compile { target c++2a } }
// { dg-final { scan-assembler-not "dummy_resume_destroy" } }
// { dg-final { scan-assembler-not "noop_coro" } }
#include <coroutine>
// PR libstdc++/95917
void
test01()
{
std::coroutine_handle<> h;
}