* [PATCH] c++: Fix coroutines on targetm.cxx.cdtor_return_this targets [PR99459]
@ 2021-03-09 9:51 Jakub Jelinek
2021-03-09 13:01 ` Nathan Sidwell
0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2021-03-09 9:51 UTC (permalink / raw)
To: Nathan Sidwell, Iain Sandoe; +Cc: gcc-patches
Hi!
The r11-7528 build_co_await changes broke coroutines on arm*-linux-gnuabi,
2780 ^FAIL.*coroutines/ in total.
The problem is that arm is targetm.cxx.cdtor_return_this target where
both ctors and dtors in the ABI return this pointer rather than
void, and build_new_method_call_1 does:
else if (call != error_mark_node
&& DECL_DESTRUCTOR_P (cand->fn)
&& !VOID_TYPE_P (TREE_TYPE (call)))
/* An explicit call of the form "x->~X()" has type
"void". However, on platforms where destructors
return "this" (i.e., those where
targetm.cxx.cdtor_returns_this is true), such calls
will appear to have a return value of pointer type
to the low-level call machinery. We do not want to
change the low-level machinery, since we want to be
able to optimize "delete f()" on such platforms as
"operator delete(~X(f()))" (rather than generating
"t = f(), ~X(t), operator delete (t)"). */
call = build_nop (void_type_node, call);
The new code in build_co_await relies on build_special_member_call
returned expression being a CALL_EXPR, but due to the build_nop
in there it is a NOP_EXPR around the CALL_EXPR. It can't be stripped
with STRIP_NOPS because void has different mode from the pointer mode.
Bootstrapped/regtested on armv7hl-linux-gnueabi and x86_64-linux, ok for trunk?
2021-03-09 Jakub Jelinek <jakub@redhat.com>
PR c++/99459
* coroutines.cc (build_co_await): Look through NOP_EXPRs in
build_special_member_call return value to find the CALL_EXPR.
--- gcc/cp/coroutines.cc.jj 2021-03-05 21:51:48.671185716 +0100
+++ gcc/cp/coroutines.cc 2021-03-08 10:53:13.187959339 +0100
@@ -868,6 +868,8 @@ build_co_await (location_t loc, tree a,
= build_special_member_call (a, complete_dtor_identifier,
NULL, a_type, LOOKUP_NORMAL,
tf_none);
+ if (dummy && CONVERT_EXPR_P (dummy))
+ dummy = TREE_OPERAND (dummy, 0);
dummy = dummy ? TREE_OPERAND (CALL_EXPR_FN (dummy), 0)
: NULL_TREE;
if (dummy && coro_diagnose_throwing_fn (dummy))
@@ -1031,6 +1033,8 @@ build_co_await (location_t loc, tree a,
= build_special_member_call (e_proxy, complete_dtor_identifier,
NULL, o_type, LOOKUP_NORMAL,
tf_none);
+ if (dummy && CONVERT_EXPR_P (dummy))
+ dummy = TREE_OPERAND (dummy, 0);
dummy = dummy ? TREE_OPERAND (CALL_EXPR_FN (dummy), 0)
: NULL_TREE;
if (dummy && coro_diagnose_throwing_fn (dummy))
Jakub
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] c++: Fix coroutines on targetm.cxx.cdtor_return_this targets [PR99459]
2021-03-09 9:51 [PATCH] c++: Fix coroutines on targetm.cxx.cdtor_return_this targets [PR99459] Jakub Jelinek
@ 2021-03-09 13:01 ` Nathan Sidwell
2021-03-09 15:23 ` [PATCH] c++, v2: " Jakub Jelinek
0 siblings, 1 reply; 4+ messages in thread
From: Nathan Sidwell @ 2021-03-09 13:01 UTC (permalink / raw)
To: Jakub Jelinek, Iain Sandoe; +Cc: gcc-patches
On 3/9/21 4:51 AM, Jakub Jelinek wrote:
> Hi!
>
> The r11-7528 build_co_await changes broke coroutines on arm*-linux-gnuabi,
> 2780 ^FAIL.*coroutines/ in total.
> The problem is that arm is targetm.cxx.cdtor_return_this target where
> both ctors and dtors in the ABI return this pointer rather than
> void, and build_new_method_call_1 does:
> else if (call != error_mark_node
> && DECL_DESTRUCTOR_P (cand->fn)
> && !VOID_TYPE_P (TREE_TYPE (call)))
> /* An explicit call of the form "x->~X()" has type
> "void". However, on platforms where destructors
> return "this" (i.e., those where
> targetm.cxx.cdtor_returns_this is true), such calls
> will appear to have a return value of pointer type
> to the low-level call machinery. We do not want to
> change the low-level machinery, since we want to be
> able to optimize "delete f()" on such platforms as
> "operator delete(~X(f()))" (rather than generating
> "t = f(), ~X(t), operator delete (t)"). */
> call = build_nop (void_type_node, call);
> The new code in build_co_await relies on build_special_member_call
> returned expression being a CALL_EXPR, but due to the build_nop
> in there it is a NOP_EXPR around the CALL_EXPR. It can't be stripped
> with STRIP_NOPS because void has different mode from the pointer mode.
>
> Bootstrapped/regtested on armv7hl-linux-gnueabi and x86_64-linux, ok for trunk?
thanks for digging into this. Looks good, but could you take the
opportunity to rewrite the conditionals to a single
if (dummy) { ... do the non-null things ... }
?
>
> 2021-03-09 Jakub Jelinek <jakub@redhat.com>
>
> PR c++/99459
> * coroutines.cc (build_co_await): Look through NOP_EXPRs in
> build_special_member_call return value to find the CALL_EXPR.
>
> --- gcc/cp/coroutines.cc.jj 2021-03-05 21:51:48.671185716 +0100
> +++ gcc/cp/coroutines.cc 2021-03-08 10:53:13.187959339 +0100
> @@ -868,6 +868,8 @@ build_co_await (location_t loc, tree a,
> = build_special_member_call (a, complete_dtor_identifier,
> NULL, a_type, LOOKUP_NORMAL,
> tf_none);
> + if (dummy && CONVERT_EXPR_P (dummy))
> + dummy = TREE_OPERAND (dummy, 0);
> dummy = dummy ? TREE_OPERAND (CALL_EXPR_FN (dummy), 0)
> : NULL_TREE;
> if (dummy && coro_diagnose_throwing_fn (dummy))
> @@ -1031,6 +1033,8 @@ build_co_await (location_t loc, tree a,
> = build_special_member_call (e_proxy, complete_dtor_identifier,
> NULL, o_type, LOOKUP_NORMAL,
> tf_none);
> + if (dummy && CONVERT_EXPR_P (dummy))
> + dummy = TREE_OPERAND (dummy, 0);
> dummy = dummy ? TREE_OPERAND (CALL_EXPR_FN (dummy), 0)
> : NULL_TREE;
> if (dummy && coro_diagnose_throwing_fn (dummy))
>
> Jakub
>
--
Nathan Sidwell
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] c++, v2: Fix coroutines on targetm.cxx.cdtor_return_this targets [PR99459]
2021-03-09 13:01 ` Nathan Sidwell
@ 2021-03-09 15:23 ` Jakub Jelinek
2021-03-09 15:35 ` Nathan Sidwell
0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2021-03-09 15:23 UTC (permalink / raw)
To: Nathan Sidwell; +Cc: Iain Sandoe, gcc-patches
On Tue, Mar 09, 2021 at 08:01:26AM -0500, Nathan Sidwell wrote:
> thanks for digging into this. Looks good, but could you take the
> opportunity to rewrite the conditionals to a single
>
> if (dummy) { ... do the non-null things ... }
>
> ?
So like this? Bootstrapped/regtested on x86_64-linux and i686-linux.
2021-03-09 Jakub Jelinek <jakub@redhat.com>
PR c++/99459
* coroutines.cc (build_co_await): Look through NOP_EXPRs in
build_special_member_call return value to find the CALL_EXPR.
Simplify.
--- gcc/cp/coroutines.cc.jj 2021-03-08 14:46:26.845072273 +0100
+++ gcc/cp/coroutines.cc 2021-03-09 14:26:19.867411700 +0100
@@ -863,16 +863,17 @@ build_co_await (location_t loc, tree a,
final awaiter, so check for a non-throwing DTOR where needed. */
tree a_type = TREE_TYPE (a);
if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (a_type))
- {
- tree dummy
+ if (tree dummy
= build_special_member_call (a, complete_dtor_identifier,
NULL, a_type, LOOKUP_NORMAL,
- tf_none);
- dummy = dummy ? TREE_OPERAND (CALL_EXPR_FN (dummy), 0)
- : NULL_TREE;
- if (dummy && coro_diagnose_throwing_fn (dummy))
- return error_mark_node;
- }
+ tf_none))
+ {
+ if (CONVERT_EXPR_P (dummy))
+ dummy = TREE_OPERAND (dummy, 0);
+ dummy = TREE_OPERAND (CALL_EXPR_FN (dummy), 0);
+ if (coro_diagnose_throwing_fn (dummy))
+ return error_mark_node;
+ }
}
}
else
@@ -1026,16 +1027,17 @@ build_co_await (location_t loc, tree a,
if (coro_diagnose_throwing_fn (awrs_func))
return error_mark_node;
if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (o_type))
- {
- tree dummy
+ if (tree dummy
= build_special_member_call (e_proxy, complete_dtor_identifier,
NULL, o_type, LOOKUP_NORMAL,
- tf_none);
- dummy = dummy ? TREE_OPERAND (CALL_EXPR_FN (dummy), 0)
- : NULL_TREE;
- if (dummy && coro_diagnose_throwing_fn (dummy))
- return error_mark_node;
- }
+ tf_none))
+ {
+ if (CONVERT_EXPR_P (dummy))
+ dummy = TREE_OPERAND (dummy, 0);
+ dummy = TREE_OPERAND (CALL_EXPR_FN (dummy), 0);
+ if (coro_diagnose_throwing_fn (dummy))
+ return error_mark_node;
+ }
}
/* We now have three call expressions, in terms of the promise, handle and
Jakub
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] c++, v2: Fix coroutines on targetm.cxx.cdtor_return_this targets [PR99459]
2021-03-09 15:23 ` [PATCH] c++, v2: " Jakub Jelinek
@ 2021-03-09 15:35 ` Nathan Sidwell
0 siblings, 0 replies; 4+ messages in thread
From: Nathan Sidwell @ 2021-03-09 15:35 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Iain Sandoe, gcc-patches
On 3/9/21 10:23 AM, Jakub Jelinek wrote:
> On Tue, Mar 09, 2021 at 08:01:26AM -0500, Nathan Sidwell wrote:
>> thanks for digging into this. Looks good, but could you take the
>> opportunity to rewrite the conditionals to a single
>>
>> if (dummy) { ... do the non-null things ... }
>>
>> ?
>
> So like this? Bootstrapped/regtested on x86_64-linux and i686-linux.
yeah, great! thank you.
>
> 2021-03-09 Jakub Jelinek <jakub@redhat.com>
>
> PR c++/99459
> * coroutines.cc (build_co_await): Look through NOP_EXPRs in
> build_special_member_call return value to find the CALL_EXPR.
> Simplify.
>
> --- gcc/cp/coroutines.cc.jj 2021-03-08 14:46:26.845072273 +0100
> +++ gcc/cp/coroutines.cc 2021-03-09 14:26:19.867411700 +0100
> @@ -863,16 +863,17 @@ build_co_await (location_t loc, tree a,
> final awaiter, so check for a non-throwing DTOR where needed. */
> tree a_type = TREE_TYPE (a);
> if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (a_type))
> - {
> - tree dummy
> + if (tree dummy
> = build_special_member_call (a, complete_dtor_identifier,
> NULL, a_type, LOOKUP_NORMAL,
> - tf_none);
> - dummy = dummy ? TREE_OPERAND (CALL_EXPR_FN (dummy), 0)
> - : NULL_TREE;
> - if (dummy && coro_diagnose_throwing_fn (dummy))
> - return error_mark_node;
> - }
> + tf_none))
> + {
> + if (CONVERT_EXPR_P (dummy))
> + dummy = TREE_OPERAND (dummy, 0);
> + dummy = TREE_OPERAND (CALL_EXPR_FN (dummy), 0);
> + if (coro_diagnose_throwing_fn (dummy))
> + return error_mark_node;
> + }
> }
> }
> else
> @@ -1026,16 +1027,17 @@ build_co_await (location_t loc, tree a,
> if (coro_diagnose_throwing_fn (awrs_func))
> return error_mark_node;
> if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (o_type))
> - {
> - tree dummy
> + if (tree dummy
> = build_special_member_call (e_proxy, complete_dtor_identifier,
> NULL, o_type, LOOKUP_NORMAL,
> - tf_none);
> - dummy = dummy ? TREE_OPERAND (CALL_EXPR_FN (dummy), 0)
> - : NULL_TREE;
> - if (dummy && coro_diagnose_throwing_fn (dummy))
> - return error_mark_node;
> - }
> + tf_none))
> + {
> + if (CONVERT_EXPR_P (dummy))
> + dummy = TREE_OPERAND (dummy, 0);
> + dummy = TREE_OPERAND (CALL_EXPR_FN (dummy), 0);
> + if (coro_diagnose_throwing_fn (dummy))
> + return error_mark_node;
> + }
> }
>
> /* We now have three call expressions, in terms of the promise, handle and
>
>
> Jakub
>
--
Nathan Sidwell
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-03-09 15:35 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-09 9:51 [PATCH] c++: Fix coroutines on targetm.cxx.cdtor_return_this targets [PR99459] Jakub Jelinek
2021-03-09 13:01 ` Nathan Sidwell
2021-03-09 15:23 ` [PATCH] c++, v2: " Jakub Jelinek
2021-03-09 15:35 ` Nathan Sidwell
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).