diff options
author | JunMa <JunMa@linux.alibaba.com> | 2020-01-21 18:18:09 +0800 |
---|---|---|
committer | JunMa <JunMa@linux.alibaba.com> | 2020-02-05 08:54:46 +0800 |
commit | 3ef39186b61939da7c658561b97f04b62973bf92 (patch) | |
tree | 5766772318711e97df9aabf30eabd54e9ac9b609 /gcc | |
parent | 81d73774ed6ee26876052c8cb915e73152ffca3a (diff) | |
download | gcc-3ef39186b61939da7c658561b97f04b62973bf92.zip gcc-3ef39186b61939da7c658561b97f04b62973bf92.tar.gz gcc-3ef39186b61939da7c658561b97f04b62973bf92.tar.bz2 |
Handle type deduction of auto and decltype(auto) with reference expression
gcc/cp
* coroutines.cc (build_co_await): Call convert_from_reference
to wrap co_await_expr with indirect_ref which avoid
reference/non-reference type confusion.
(co_await_expander): Sink to call_expr if await_resume
is wrapped by indirect_ref.
gcc/testsuite
* g++.dg/coroutines/co-await-14-return-ref-to-auto.C: New test.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 9 | ||||
-rw-r--r-- | gcc/cp/coroutines.cc | 12 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/coroutines/torture/co-await-14-return-ref-to-auto.C | 45 |
4 files changed, 67 insertions, 3 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 4e4235d..a54c8db 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,12 @@ +2020-02-05 Jun Ma <JunMa@linux.alibaba.com> + + * coroutines.cc (build_co_await): Call convert_from_reference + to wrap co_await_expr with indirect_ref which avoid + reference/non-reference type confusion. + + (co_await_expander): Sink to call_expr if await_resume + is wrapped by indirect_ref. + 2020-02-04 Jason Merrill <jason@redhat.com> PR c++/93551 diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc index d5ff675..e24ea7b 100644 --- a/gcc/cp/coroutines.cc +++ b/gcc/cp/coroutines.cc @@ -803,9 +803,12 @@ build_co_await (location_t loc, tree a, suspend_point_kind suspend_kind) TREE_VEC_ELT (awaiter_calls, 1) = awsp_call; /* await_suspend(). */ TREE_VEC_ELT (awaiter_calls, 2) = awrs_call; /* await_resume(). */ - return build5_loc (loc, CO_AWAIT_EXPR, TREE_TYPE (awrs_call), a, - e_proxy, o, awaiter_calls, - build_int_cst (integer_type_node, (int) suspend_kind)); + tree await_expr = build5_loc (loc, CO_AWAIT_EXPR, + TREE_TYPE (TREE_TYPE (awrs_func)), + a, e_proxy, o, awaiter_calls, + build_int_cst (integer_type_node, + (int) suspend_kind)); + return convert_from_reference (await_expr); } tree @@ -1566,6 +1569,9 @@ co_await_expander (tree *stmt, int * /*do_subtree*/, void *d) /* This will produce the value (if one is provided) from the co_await expression. */ tree resume_call = TREE_VEC_ELT (awaiter_calls, 2); /* await_resume(). */ + if (REFERENCE_REF_P (resume_call)) + /* Sink to await_resume call_expr. */ + resume_call = TREE_OPERAND (resume_call, 0); switch (stmt_code) { default: /* not likely to work .. but... */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d2dc664..3b2be71 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2020-02-05 Jun Ma <JunMa@linux.alibaba.com> + + * g++.dg/coroutines/co-await-14-return-ref-to-auto.C: New test. + 2020-02-04 David Malcolm <dmalcolm@redhat.com> * gcc.dg/analyzer/data-model-1.c (struct coord): Convert fields diff --git a/gcc/testsuite/g++.dg/coroutines/torture/co-await-14-return-ref-to-auto.C b/gcc/testsuite/g++.dg/coroutines/torture/co-await-14-return-ref-to-auto.C new file mode 100644 index 0000000..0a7c035 --- /dev/null +++ b/gcc/testsuite/g++.dg/coroutines/torture/co-await-14-return-ref-to-auto.C @@ -0,0 +1,45 @@ +// { dg-do run } + +/* The simplest valued co_await we can do. */ + +#include "../coro.h" + +// boiler-plate for tests of codegen +#include "../coro1-ret-int-yield-int.h" + + +coro1 +f () +{ + int t1 = 5; + int t2 = 5; + auto gX = co_await coro1::suspend_always_intrefprt{t1}; + if (gX != t1) + abort(); + decltype(auto) gX1 = co_await coro1::suspend_always_intrefprt{t2}; + if (&gX1 != &t2) + abort(); + co_return t1 + 10; +} + +int main () +{ + PRINT ("main: create coro1"); + struct coro1 f_coro = f (); + if (f_coro.handle.done()) + { + PRINT ("main: we should not be 'done' [1]"); + abort (); + } + PRINT ("main: resuming [1] initial suspend"); + while (!f_coro.handle.done()) + f_coro.handle.resume(); + /* we should now have returned with the co_return (15) */ + if (!f_coro.handle.done()) + { + PRINT ("main: we should be 'done' "); + abort (); + } + puts ("main: done"); + return 0; +} |