[gcc r11-4120] libstdc++: Define noop coroutine details private and inline [PR 95917]
Jonathan Wakely
redi@gcc.gnu.org
Tue Oct 20 10:38:03 GMT 2020
https://gcc.gnu.org/g:94fd05f1f76faca9dc9033b55d44c960155d38e9
commit r11-4120-g94fd05f1f76faca9dc9033b55d44c960155d38e9
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Tue Oct 20 11:19:58 2020 +0100
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.
Diff:
---
libstdc++-v3/include/std/coroutine | 30 ++++++++++++---------
.../testsuite/18_support/coroutines/95917.cc | 31 ++++++++++++++++++++++
2 files changed, 48 insertions(+), 13 deletions(-)
diff --git a/libstdc++-v3/include/std/coroutine b/libstdc++-v3/include/std/coroutine
index 6e1cf141579..2b635b982e0 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<noop_coroutine_promise>;
+ 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 00000000000..5c9cf57e001
--- /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
+// <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;
+}
More information about the Libstdc++-cvs
mailing list