diff mbox series

c++: Enable coroutines with -std=c++20.

Message ID 20200514204123.1886-1-jason@redhat.com
State New
Headers show
Series c++: Enable coroutines with -std=c++20. | expand

Commit Message

Jason Merrill May 14, 2020, 8:41 p.m. UTC
Now that GCC 10 is out it seems time.  People can still choose to disable
coroutines with -fno-coroutines.

This also switches the coroutines testsuite to run in C++20 mode.  The
change to coro.h is needed for co-await-11-forwarding.C; we could
alternatively #include <utility> just in that file.

Iain, does this make sense to you?

gcc/c-family/ChangeLog
2020-05-14  Jason Merrill  <jason@redhat.com>

	* c-opts.c (set_std_cxx20): Set flag_coroutines.

gcc/testsuite/ChangeLog
2020-05-14  Jason Merrill  <jason@redhat.com>

	* g++.dg/coroutines/coro.h: Always #include <utility>.
	* g++.dg/coroutines/coroutines.exp (DEFAULT_COROFLAGS): Use
	-std=c++20.
---
 gcc/testsuite/g++.dg/coroutines/coro.h         | 10 ++--------
 gcc/c-family/c-opts.c                          |  7 ++++---
 gcc/testsuite/g++.dg/coroutines/coroutines.exp |  2 +-
 3 files changed, 7 insertions(+), 12 deletions(-)


base-commit: 4e1592f8e1d6366699e05c0824fc3dc39ca7314b

Comments

Iain Sandoe May 14, 2020, 8:56 p.m. UTC | #1
Jason Merrill via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:

> Now that GCC 10 is out it seems time.  People can still choose to disable
> coroutines with -fno-coroutines.

There’s one pass that has to run for all functions, the remainder of the work
is gated on the function being a coroutine.

If there’s a hit found from that one pass, we can think about solutions.
[The issue is that any (non-coro) function could, potentially, contain a
__builtin_coro_xxxxx, so there’s no way to gate the scan to lower those
once -fcoroutines is on].

> This also switches the coroutines testsuite to run in C++20 mode.

I’m not sure if there’s benefit to doing some testing with C++17 (or even 14)
the idea was not to bake anything in that precluded coros working for 14+
However, the suite does take time, so it would probably be the wrong thing to
make it run for all three.

>  The
> change to coro.h is needed for co-await-11-forwarding.C; we could
> alternatively #include <utility> just in that file.

let’s see if there’s a significant hit on the test-time we can always move it
if so.

> Iain, does this make sense to you?

yes, we just ran out of time before 10.1.

thanks for doing this, it was kinda on my list but lower than bug-fixing ;)
Iain

>
> gcc/c-family/ChangeLog
> 2020-05-14  Jason Merrill  <jason@redhat.com>
>
> 	* c-opts.c (set_std_cxx20): Set flag_coroutines.
>
> gcc/testsuite/ChangeLog
> 2020-05-14  Jason Merrill  <jason@redhat.com>
>
> 	* g++.dg/coroutines/coro.h: Always #include <utility>.
> 	* g++.dg/coroutines/coroutines.exp (DEFAULT_COROFLAGS): Use
> 	-std=c++20.
> ---
> gcc/testsuite/g++.dg/coroutines/coro.h         | 10 ++--------
> gcc/c-family/c-opts.c                          |  7 ++++---
> gcc/testsuite/g++.dg/coroutines/coroutines.exp |  2 +-
> 3 files changed, 7 insertions(+), 12 deletions(-)
>
> diff --git a/gcc/testsuite/g++.dg/coroutines/coro.h  
> b/gcc/testsuite/g++.dg/coroutines/coro.h
> index fccfe418616..02d26602727 100644
> --- a/gcc/testsuite/g++.dg/coroutines/coro.h
> +++ b/gcc/testsuite/g++.dg/coroutines/coro.h
> @@ -2,20 +2,12 @@
>
> #include <coroutine>
>
> -#  if __clang__
> -#    include <utility>
> -#  endif
> -
> namespace coro = std;
>
> #elif __has_include(<experimental/coroutine>)
>
> #include <experimental/coroutine>
>
> -#  if __clang__
> -#    include <utility>
> -#  endif
> -
> namespace coro = std::experimental;
>
> #else
> @@ -143,6 +135,8 @@ extern "C" int printf (const char *, ...);
>
> #include <cstdlib> /* for abort () */
>
> +#include <utility> /* for std::forward */
> +
> #ifndef OUTPUT
> #  define PRINT(X)
> #  define PRINTF (void)
> diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
> index bd617d3df18..7695e88c130 100644
> --- a/gcc/c-family/c-opts.c
> +++ b/gcc/c-family/c-opts.c
> @@ -1722,7 +1722,7 @@ set_std_cxx17 (int iso)
>   lang_hooks.name = "GNU C++17";
> }
>
> -/* Set the C++ 202a draft standard (without GNU extensions if ISO).  */
> +/* Set the C++ 2020 standard (without GNU extensions if ISO).  */
> static void
> set_std_cxx20 (int iso)
> {
> @@ -1734,9 +1734,10 @@ set_std_cxx20 (int iso)
>   flag_isoc94 = 1;
>   flag_isoc99 = 1;
>   flag_isoc11 = 1;
> -  /* C++20 includes concepts. */
> +  /* C++20 includes coroutines. */
> +  flag_coroutines = true;
>   cxx_dialect = cxx20;
> -  lang_hooks.name = "GNU C++17"; /* Pretend C++17 until  
> standardization.  */
> +  lang_hooks.name = "GNU C++20";
> }
>
> /* Args to -d specify what to dump.  Silently ignore
> diff --git a/gcc/testsuite/g++.dg/coroutines/coroutines.exp  
> b/gcc/testsuite/g++.dg/coroutines/coroutines.exp
> index e7fd4dac461..1bef98ae54d 100644
> --- a/gcc/testsuite/g++.dg/coroutines/coroutines.exp
> +++ b/gcc/testsuite/g++.dg/coroutines/coroutines.exp
> @@ -29,7 +29,7 @@ if ![info exists DEFAULT_CXXFLAGS] then {
> }
>
> set DEFAULT_COROFLAGS $DEFAULT_CXXFLAGS
> -lappend DEFAULT_COROFLAGS "-std=c++17" "-fcoroutines"
> +lappend DEFAULT_COROFLAGS "-std=c++20"
>
> dg-init
>
>
> base-commit: 4e1592f8e1d6366699e05c0824fc3dc39ca7314b
> -- 
> 2.18.1
diff mbox series

Patch

diff --git a/gcc/testsuite/g++.dg/coroutines/coro.h b/gcc/testsuite/g++.dg/coroutines/coro.h
index fccfe418616..02d26602727 100644
--- a/gcc/testsuite/g++.dg/coroutines/coro.h
+++ b/gcc/testsuite/g++.dg/coroutines/coro.h
@@ -2,20 +2,12 @@ 
 
 #include <coroutine>
 
-#  if __clang__
-#    include <utility>
-#  endif
-
 namespace coro = std;
 
 #elif __has_include(<experimental/coroutine>)
 
 #include <experimental/coroutine>
 
-#  if __clang__
-#    include <utility>
-#  endif
-
 namespace coro = std::experimental;
 
 #else
@@ -143,6 +135,8 @@  extern "C" int printf (const char *, ...);
 
 #include <cstdlib> /* for abort () */
 
+#include <utility> /* for std::forward */
+
 #ifndef OUTPUT
 #  define PRINT(X)
 #  define PRINTF (void)
diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
index bd617d3df18..7695e88c130 100644
--- a/gcc/c-family/c-opts.c
+++ b/gcc/c-family/c-opts.c
@@ -1722,7 +1722,7 @@  set_std_cxx17 (int iso)
   lang_hooks.name = "GNU C++17";
 }
 
-/* Set the C++ 202a draft standard (without GNU extensions if ISO).  */
+/* Set the C++ 2020 standard (without GNU extensions if ISO).  */
 static void
 set_std_cxx20 (int iso)
 {
@@ -1734,9 +1734,10 @@  set_std_cxx20 (int iso)
   flag_isoc94 = 1;
   flag_isoc99 = 1;
   flag_isoc11 = 1;
-  /* C++20 includes concepts. */
+  /* C++20 includes coroutines. */
+  flag_coroutines = true;
   cxx_dialect = cxx20;
-  lang_hooks.name = "GNU C++17"; /* Pretend C++17 until standardization.  */
+  lang_hooks.name = "GNU C++20";
 }
 
 /* Args to -d specify what to dump.  Silently ignore
diff --git a/gcc/testsuite/g++.dg/coroutines/coroutines.exp b/gcc/testsuite/g++.dg/coroutines/coroutines.exp
index e7fd4dac461..1bef98ae54d 100644
--- a/gcc/testsuite/g++.dg/coroutines/coroutines.exp
+++ b/gcc/testsuite/g++.dg/coroutines/coroutines.exp
@@ -29,7 +29,7 @@  if ![info exists DEFAULT_CXXFLAGS] then {
 }
 
 set DEFAULT_COROFLAGS $DEFAULT_CXXFLAGS
-lappend DEFAULT_COROFLAGS "-std=c++17" "-fcoroutines"
+lappend DEFAULT_COROFLAGS "-std=c++20"
 
 dg-init