public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Iain Sandoe <iain@sandoe.co.uk>
To: GCC Patches <gcc-patches@gcc.gnu.org>, libstdc++ <libstdc++@gcc.gnu.org>
Subject: [C++ coroutines 1/6] Common code and base definitions.
Date: Sun, 17 Nov 2019 10:24:00 -0000	[thread overview]
Message-ID: <285E6AA6-17E6-4E7F-9F37-852707896DA1@sandoe.co.uk> (raw)
In-Reply-To: <F5F88589-1A8E-4311-AFC8-79E75C1C14C8@sandoe.co.uk>

This part of the patch series provides the gating flag, the keywords,
cpp defines etc.

gcc/ChangeLog:

2019-11-17  Iain Sandoe  <iain@sandoe.co.uk>

	* doc/invoke.texi: Document the fcoroutines command line
	switch.

gcc/c-family/ChangeLog:

2019-11-17  Iain Sandoe  <iain@sandoe.co.uk>

	* c-common.c (co_await, co_yield, co_return): New.
	* c-common.h (RID_CO_AWAIT, RID_CO_YIELD,
	RID_CO_RETURN): New enumeration values.
	(D_CXX_COROUTINES): Bit to identify coroutines are active.
	(D_CXX_COROUTINES_FLAGS): Guard for coroutine keywords.
	* c-cppbuiltin.c (__cpp_coroutines): New cpp define.
	* c.opt (fcoroutines): New command-line switch.

gcc/cp/ChangeLog:

2019-11-17  Iain Sandoe  <iain@sandoe.co.uk>

	* cp-tree.h (lang_decl-fn): coroutine_p, new bit.
	* lex.c (init_reswords): Enable keywords when the coroutine flag
	is set,
	* operators.def (co_await): New operator.
---
 gcc/c-family/c-common.c     |  5 +++++
 gcc/c-family/c-common.h     |  5 +++++
 gcc/c-family/c-cppbuiltin.c |  2 ++
 gcc/c-family/c.opt          |  4 ++++
 gcc/cp/cp-tree.h            | 17 ++++++++++++++++-
 gcc/cp/lex.c                |  2 ++
 gcc/cp/operators.def        |  1 +
 gcc/doc/invoke.texi         |  4 ++++
 8 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 4881199..8be92a6 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -536,6 +536,11 @@ const struct c_common_resword c_common_reswords[] =
   { "concept",		RID_CONCEPT,	D_CXX_CONCEPTS_FLAGS | D_CXXWARN },
   { "requires", 	RID_REQUIRES,	D_CXX_CONCEPTS_FLAGS | D_CXXWARN },
 
+  /* Coroutines-related keywords */
+  { "co_await",		RID_CO_AWAIT,	D_CXX_COROUTINES_FLAGS | D_CXXWARN },
+  { "co_yield",		RID_CO_YIELD,	D_CXX_COROUTINES_FLAGS | D_CXXWARN },
+  { "co_return", 	RID_CO_RETURN,	D_CXX_COROUTINES_FLAGS | D_CXXWARN },
+
   /* These Objective-C keywords are recognized only immediately after
      an '@'.  */
   { "compatibility_alias", RID_AT_ALIAS,	D_OBJC },
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index 80a8c9f..6ec0910 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -189,6 +189,9 @@ enum rid
   /* C++ concepts */
   RID_CONCEPT, RID_REQUIRES,
 
+  /* C++ coroutines */
+  RID_CO_AWAIT, RID_CO_YIELD, RID_CO_RETURN,
+
   /* C++ transactional memory.  */
   RID_ATOMIC_NOEXCEPT, RID_ATOMIC_CANCEL, RID_SYNCHRONIZED,
 
@@ -433,9 +436,11 @@ extern machine_mode c_default_pointer_mode;
 #define D_TRANSMEM	0X0800	/* C++ transactional memory TS.  */
 #define D_CXX_CHAR8_T	0X1000	/* In C++, only with -fchar8_t.  */
 #define D_CXX20		0x2000  /* In C++, C++20 only.  */
+#define D_CXX_COROUTINES 0x4000  /* In C++, only with coroutines.  */
 
 #define D_CXX_CONCEPTS_FLAGS D_CXXONLY | D_CXX_CONCEPTS
 #define D_CXX_CHAR8_T_FLAGS D_CXXONLY | D_CXX_CHAR8_T
+#define D_CXX_COROUTINES_FLAGS (D_CXXONLY | D_CXX_COROUTINES)
 
 /* The reserved keyword table.  */
 extern const struct c_common_resword c_common_reswords[];
diff --git a/gcc/c-family/c-cppbuiltin.c b/gcc/c-family/c-cppbuiltin.c
index cf3d437..6299d47 100644
--- a/gcc/c-family/c-cppbuiltin.c
+++ b/gcc/c-family/c-cppbuiltin.c
@@ -1000,6 +1000,8 @@ c_cpp_builtins (cpp_reader *pfile)
           else
             cpp_define (pfile, "__cpp_concepts=201507L");
         }
+      if (flag_coroutines)
+	cpp_define (pfile, "__cpp_coroutines=201902L"); /* n4835, C++20 CD */
       if (flag_tm)
 	/* Use a value smaller than the 201505 specified in
 	   the TS, since we don't yet support atomic_cancel.  */
diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 914a2f0..62bf4f1 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -1469,6 +1469,10 @@ fconstexpr-ops-limit=
 C++ ObjC++ Joined RejectNegative Host_Wide_Int Var(constexpr_ops_limit) Init(33554432)
 -fconstexpr-ops-limit=<number>	Specify maximum number of constexpr operations during a single constexpr evaluation.
 
+fcoroutines
+C++ LTO Var(flag_coroutines)
+Enable C++ coroutines (experimental).
+
 fdebug-cpp
 C ObjC C++ ObjC++
 Emit debug annotations during preprocessing.
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index adc021b..6fb99d8 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -2696,7 +2696,9 @@ struct GTY(()) lang_decl_fn {
   unsigned has_dependent_explicit_spec_p : 1;
   unsigned immediate_fn_p : 1;
   unsigned maybe_deleted : 1;
-  unsigned spare : 10;
+  unsigned coroutine_p : 1;
+
+  unsigned spare : 9;
 
   /* 32-bits padding on 64-bit host.  */
 
@@ -4982,6 +4984,13 @@ more_aggr_init_expr_args_p (const aggr_init_expr_arg_iterator *iter)
 #define QUALIFIED_NAME_IS_TEMPLATE(NODE) \
   (TREE_LANG_FLAG_1 (SCOPE_REF_CHECK (NODE)))
 
+/* [coroutines]
+*/
+
+/* True if NODE is a co-routine FUNCTION_DECL.  */
+#define DECL_COROUTINE_P(NODE) \
+  (LANG_DECL_FN_CHECK (DECL_COMMON_CHECK (NODE))->coroutine_p)
+
 /* True for an OMP_ATOMIC that has dependent parameters.  These are stored
    as an expr in operand 1, and integer_zero_node or clauses in operand 0.  */
 #define OMP_ATOMIC_DEPENDENT_P(NODE) \
@@ -7892,6 +7901,12 @@ extern tree cp_ubsan_maybe_instrument_downcast	(location_t, tree, tree, tree);
 extern tree cp_ubsan_maybe_instrument_cast_to_vbase (location_t, tree, tree);
 extern void cp_ubsan_maybe_initialize_vtbl_ptrs (tree);
 
+/* In coroutines.cc */
+extern tree finish_co_return_stmt		(location_t, tree);
+extern tree finish_co_await_expr		(location_t, tree);
+extern tree finish_co_yield_expr		(location_t, tree);
+extern bool morph_fn_to_coro			(tree, tree *, tree *);
+
 /* Inline bodies.  */
 
 inline tree
diff --git a/gcc/cp/lex.c b/gcc/cp/lex.c
index 25529e7..cd8dd80 100644
--- a/gcc/cp/lex.c
+++ b/gcc/cp/lex.c
@@ -233,6 +233,8 @@ init_reswords (void)
     mask |= D_CXX20;
   if (!flag_concepts)
     mask |= D_CXX_CONCEPTS;
+  if (!flag_coroutines)
+    mask |= D_CXX_COROUTINES;
   if (!flag_tm)
     mask |= D_TRANSMEM;
   if (!flag_char8_t)
diff --git a/gcc/cp/operators.def b/gcc/cp/operators.def
index ee0a4c1..3e5bd1f 100644
--- a/gcc/cp/operators.def
+++ b/gcc/cp/operators.def
@@ -87,6 +87,7 @@ DEF_OPERATOR ("++", PREINCREMENT_EXPR, "pp", OVL_OP_FLAG_UNARY)
 DEF_OPERATOR ("--", PREDECREMENT_EXPR, "mm", OVL_OP_FLAG_UNARY)
 DEF_OPERATOR ("->", COMPONENT_REF, "pt", OVL_OP_FLAG_UNARY)
 DEF_OPERATOR ("sizeof", SIZEOF_EXPR, "sz", OVL_OP_FLAG_UNARY)
+DEF_OPERATOR ("co_await", CO_AWAIT_EXPR, "aw", OVL_OP_FLAG_UNARY)
 
 /* These are extensions.  */
 DEF_OPERATOR ("alignof", ALIGNOF_EXPR, "az", OVL_OP_FLAG_UNARY)
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 00eb7e7..7be3bfb 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -2567,6 +2567,10 @@ of a loop too many expressions need to be evaluated, the resulting constexpr
 evaluation might take too long.
 The default is 33554432 (1<<25).
 
+@item -fcoroutines
+@opindex fcoroutines
+Enable support for the C++ coroutines extension (experimental).
+
 @item -fno-elide-constructors
 @opindex fno-elide-constructors
 @opindex felide-constructors
-- 
2.8.1


  reply	other threads:[~2019-11-17 10:24 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-17 10:23 [C++ coroutines 0/6] Implement C++ coroutines Iain Sandoe
2019-11-17 10:24 ` Iain Sandoe [this message]
2019-11-17 10:24   ` [C++ coroutines 2/6] Define builtins and internal functions Iain Sandoe
2019-11-17 10:26     ` [C++ coroutines 3/6] Front end parsing and transforms Iain Sandoe
2019-11-17 10:26       ` [C++ coroutines 4/6] Middle end expanders " Iain Sandoe
2019-11-17 10:27         ` [C++ coroutines 5/6] Standard library header Iain Sandoe
2019-11-17 10:28           ` [C++ coroutines 6/6] Testsuite Iain Sandoe
2019-11-19 10:01             ` Richard Biener
2020-01-09 12:40               ` [C++ coroutines 6/7, v2] Testsuite Iain Sandoe
2020-01-09 13:00                 ` Iain Sandoe
2020-01-09 13:17                 ` Richard Biener
2019-11-20 11:13             ` [C++ coroutines 6/6] Testsuite JunMa
2019-11-20 11:22               ` Iain Sandoe
2019-11-20 13:11                 ` JunMa
2019-11-17 16:19           ` [C++ coroutines 5/6] Standard library header Jonathan Wakely
2020-01-09 12:39             ` [C++ coroutines 5/7, v2] " Iain Sandoe
2020-01-09 13:50               ` Jonathan Wakely
2020-01-09 19:57                 ` [C++ coroutines 5/7, v3] " Iain Sandoe
2020-01-09 21:21                   ` Jonathan Wakely
2019-11-19 10:00         ` [C++ coroutines 4/6] Middle end expanders and transforms Richard Biener
2020-01-09 12:38           ` [C++ coroutines 4/7, v2] " Iain Sandoe
2020-01-09 14:38             ` Richard Biener
2019-11-18 13:23       ` [C++ coroutines 3/6] Front end parsing " Nathan Sidwell
2019-11-19 18:40       ` Nathan Sidwell
2020-01-09 12:37         ` [C++ coroutines 3/7, v2] " Iain Sandoe
2019-11-17 16:54     ` [C++ coroutines 2/6] Define builtins and internal functions Jeff Law
2020-01-09 12:36       ` [C++ coroutines 2/7, v2] " Iain Sandoe
2019-11-17 15:49   ` [C++ coroutines 1/6] Common code and base definitions Jeff Law
2020-01-09 12:36     ` [C++ coroutines 1/7] " Iain Sandoe
2019-11-18 12:35 ` [C++ coroutines 0/6] Implement C++ coroutines Nathan Sidwell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=285E6AA6-17E6-4E7F-9F37-852707896DA1@sandoe.co.uk \
    --to=iain@sandoe.co.uk \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).