On 7/16/24 5:55 PM, Andi Kleen wrote:
On Tue, Jul 16, 2024 at 12:52:31PM -0700, Andi Kleen wrote:
On Tue, Jul 16, 2024 at 02:51:13PM -0400, Jason Merrill wrote:
On 7/16/24 12:18 PM, Andi Kleen wrote:
On Tue, Jul 16, 2024 at 11:17:14AM -0400, Jason Merrill wrote:
On 7/16/24 11:15 AM, Andi Kleen wrote:
In the adjusted test it looks like the types of f and g match, so I wouldn't
expect an error.

Good point! Missing the forest for the trees.

Anyways are the C++ patches ok with this change?

I'm still looking for a test which does error because the types are
different.

Like this?

Where the called function returns C and the callee function does not.

In this case the attribute seems to get lost and it succeeds.

This somewhat hackish patch fixes it here, to handle the case
of a TARGET_EXPR where the CALL_EXPR is in the cleanup. extract_call
bails on that.

The CALL_EXPR in the cleanup is calling the destructor, that's not what we're trying to tail-call.

I think the problem here is that the call to f<C> is represented with an AGGR_INIT_EXPR instead of CALL_EXPR, so you need to handle the flag on that tree_code as well.

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 3b914089a6e2..8753aa51da52 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -21124,6 +21124,10 @@ tsubst_expr (tree t, tree args, tsubst_flags_t 
complain, tree in_decl)
                  CALL_EXPR_REVERSE_ARGS (call) = rev;
                  if (TREE_CODE (call) == CALL_EXPR)
                    CALL_EXPR_MUST_TAIL_CALL (call) = mtc;
+                 else if (mtc
+                          && TREE_CODE (ret) == TARGET_EXPR
+                          && TREE_CODE (TARGET_EXPR_CLEANUP (ret)) == 
CALL_EXPR)
+                   CALL_EXPR_MUST_TAIL_CALL (TARGET_EXPR_CLEANUP (ret)) = mtc;
                }
            if (warning_suppressed_p (t, OPT_Wpessimizing_move))
              /* This also suppresses -Wredundant-move.  */


Reply via email to