From fd9e021c70edf459e5d700af90bfe005dc0afb3b Mon Sep 17 00:00:00 2001 From: JunMa Date: Wed, 5 Feb 2020 13:46:59 +0800 Subject: [PATCH] Build coroutine expression with unknown_type in processing_template_decl phase. gcc/cp * coroutines.cc (finish_co_await_expr): Build co_await_expr with unknown_type_node. (finish_co_yield_expr): Ditto. *pt.c (type_dependent_expression_p): Set co_await/yield_expr with unknown type as dependent. gcc/testsuite * g++.dg/coroutines/torture/co-await-14-template-traits.C: New test. --- gcc/cp/ChangeLog | 8 +++++++ gcc/cp/coroutines.cc | 6 ++--- gcc/cp/pt.c | 5 ++++ gcc/testsuite/ChangeLog | 4 ++++ .../torture/co-await-14-template-traits.C | 24 +++++++++++++++++++ 5 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/coroutines/torture/co-await-14-template-traits.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index bfe8d7949b2..edc088ee51d 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2020-03-03 Jun Ma + + * coroutines.cc (finish_co_await_expr): Build co_await_expr + with unknown_type_node. + (finish_co_yield_expr): Ditto. + *pt.c (type_dependent_expression_p): Set co_await/yield_expr + with unknown type as dependent. + 2020-03-02 Iain Sandoe * coroutines.cc (struct local_var_info): Adjust to remove the diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc index 303e6e83d54..966ec0583aa 100644 --- a/gcc/cp/coroutines.cc +++ b/gcc/cp/coroutines.cc @@ -847,8 +847,8 @@ finish_co_await_expr (location_t kw, tree expr) /* If we don't know the promise type, we can't proceed. */ tree functype = TREE_TYPE (current_function_decl); if (dependent_type_p (functype) || type_dependent_expression_p (expr)) - return build5_loc (kw, CO_AWAIT_EXPR, TREE_TYPE (expr), expr, NULL_TREE, - NULL_TREE, NULL_TREE, integer_zero_node); + return build5_loc (kw, CO_AWAIT_EXPR, unknown_type_node, expr, + NULL_TREE, NULL_TREE, NULL_TREE, integer_zero_node); } /* We must be able to look up the "await_transform" method in the scope of @@ -925,7 +925,7 @@ finish_co_yield_expr (location_t kw, tree expr) tree functype = TREE_TYPE (current_function_decl); /* If we don't know the promise type, we can't proceed. */ if (dependent_type_p (functype) || type_dependent_expression_p (expr)) - return build2_loc (kw, CO_YIELD_EXPR, TREE_TYPE (expr), expr, + return build2_loc (kw, CO_YIELD_EXPR, unknown_type_node, expr, NULL_TREE); } diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 622c70b352f..230331f60cb 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -26701,6 +26701,11 @@ type_dependent_expression_p (tree expression) if (TREE_CODE (expression) == SCOPE_REF) return false; + /* CO_AWAIT/YIELD_EXPR with unknown type is always dependent. */ + if (TREE_CODE (expression) == CO_AWAIT_EXPR + || TREE_CODE (expression) == CO_YIELD_EXPR) + return true; + if (BASELINK_P (expression)) { if (BASELINK_OPTYPE (expression) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5eae7d8173c..6418eb2fd94 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2020-03-03 Jun Ma + + * g++.dg/coroutines/torture/co-await-14-template-traits.C: New test. + 2020-03-02 David Malcolm * gcc.dg/analyzer/CVE-2005-1689-dedupe-issue.c: Add diff --git a/gcc/testsuite/g++.dg/coroutines/torture/co-await-14-template-traits.C b/gcc/testsuite/g++.dg/coroutines/torture/co-await-14-template-traits.C new file mode 100644 index 00000000000..4e670b1c308 --- /dev/null +++ b/gcc/testsuite/g++.dg/coroutines/torture/co-await-14-template-traits.C @@ -0,0 +1,24 @@ +// { dg-do compile } +// Test we create co_await_expr with dependent type rather than type of awaitable class + +#include "../coro.h" +#include "../coro1-ret-int-yield-int.h" +#include + +struct TestAwaiter { + int recent_test; + TestAwaiter(int test) : recent_test{test} {} + bool await_ready() { return true; } + void await_suspend(coro::coroutine_handle<>) {} + int await_resume() { return recent_test;} + void return_value(int x) { recent_test = x;} +}; + +template +coro1 test_temparg (std::chrono::duration dur) +{ + auto sum = co_await TestAwaiter(1); + if (!sum) + dur.count(); + co_return 0; +} -- 2.30.2