From 94fd05f1f76faca9dc9033b55d44c960155d38e9 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Tue, 20 Oct 2020 11:19:58 +0100 Subject: [PATCH] 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. 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. --- libstdc++-v3/include/std/coroutine | 30 ++++++++++++--------- .../testsuite/18_support/coroutines/95917.cc | 31 ++++++++++++++++++++++ 2 files changed, 48 insertions(+), 13 deletions(-) create mode 100644 libstdc++-v3/testsuite/18_support/coroutines/95917.cc diff --git a/libstdc++-v3/include/std/coroutine b/libstdc++-v3/include/std/coroutine index 6e1cf14..2b635b9 100644 --- a/libstdc++-v3/include/std/coroutine +++ b/libstdc++-v3/include/std/coroutine @@ -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 (*__r)() = __dummy_resume_destroy; + void (*__d)() = __dummy_resume_destroy; + struct noop_coroutine_promise __p; + }; + + static __frame _S_fr; - void* _M_fr_ptr = (void*) &__noop_coro_fr; + explicit coroutine_handle() noexcept = default; + + void* _M_fr_ptr = &_S_fr; }; using noop_coroutine_handle = coroutine_handle; + inline noop_coroutine_handle::__frame + noop_coroutine_handle::_S_fr{}; + inline noop_coroutine_handle noop_coroutine() noexcept { return noop_coroutine_handle(); diff --git a/libstdc++-v3/testsuite/18_support/coroutines/95917.cc b/libstdc++-v3/testsuite/18_support/coroutines/95917.cc new file mode 100644 index 0000000..5c9cf57 --- /dev/null +++ b/libstdc++-v3/testsuite/18_support/coroutines/95917.cc @@ -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 +// . + +// { 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 + +// PR libstdc++/95917 + +void +test01() +{ + std::coroutine_handle<> h; +} -- 2.7.4