https://gcc.gnu.org/g:2e3c91786a981f2d68600e2d7b2e25a766e59c21

commit r15-9454-g2e3c91786a981f2d68600e2d7b2e25a766e59c21
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Mon Apr 14 19:31:23 2025 +0200

    pretty-print, expand: Print [must tail call] for CALL_EXPRs and fix up 
maybe_complain_about_tail_call [PR119718]
    
    Andrew P. mentioned earlier he'd like to see in the dump files a note
    whether it was a failed must tail call or not.
    We already print that on the tailc/musttail pass side, because
    print_gimple_stmt prints [must tail call] after the musttail calls.
    The first hunk below does it for GENERIC CALL_EXPRs too (which is needed
    for the expand diagnostics).  That isn't enough though, because the
    error on it was done first and then CALL_EXPR_MUST_TAIL_CALL flag was
    cleared, so the dump didn't have it anymore.  I've reordered the
    dump printing with error, so that it works properly.
    
    2025-04-14  Jakub Jelinek  <ja...@redhat.com>
    
            PR tree-optimization/119718
            * tree-pretty-print.cc (dump_generic_node) <case CALL_EXPR>: Dump
            also CALL_EXPR_MUST_TAIL_CALL flag.
            * calls.cc (maybe_complain_about_tail_call): Emit error about
            CALL_EXPR_MUST_TAIL_CALL only after emitting dump message, not 
before
            it.

Diff:
---
 gcc/calls.cc             | 10 +++++-----
 gcc/tree-pretty-print.cc |  2 ++
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/gcc/calls.cc b/gcc/calls.cc
index 372fab317f6f..076e046a8ef1 100644
--- a/gcc/calls.cc
+++ b/gcc/calls.cc
@@ -1273,11 +1273,6 @@ void
 maybe_complain_about_tail_call (tree call_expr, const char *reason)
 {
   gcc_assert (TREE_CODE (call_expr) == CALL_EXPR);
-  if (CALL_EXPR_MUST_TAIL_CALL (call_expr))
-    {
-      error_at (EXPR_LOCATION (call_expr), "cannot tail-call: %s", reason);
-      CALL_EXPR_MUST_TAIL_CALL (call_expr) = 0;
-    }
   if (CALL_EXPR_TAILCALL (call_expr)
       && dump_file
       && (dump_flags & TDF_DETAILS))
@@ -1286,6 +1281,11 @@ maybe_complain_about_tail_call (tree call_expr, const 
char *reason)
       print_generic_expr (dump_file, call_expr, TDF_SLIM);
       fprintf (dump_file, "\n");
     }
+  if (CALL_EXPR_MUST_TAIL_CALL (call_expr))
+    {
+      error_at (EXPR_LOCATION (call_expr), "cannot tail-call: %s", reason);
+      CALL_EXPR_MUST_TAIL_CALL (call_expr) = 0;
+    }
 }
 
 /* Fill in ARGS_SIZE and ARGS array based on the parameters found in
diff --git a/gcc/tree-pretty-print.cc b/gcc/tree-pretty-print.cc
index a2a4f5bfa2f1..c1a21e77bd29 100644
--- a/gcc/tree-pretty-print.cc
+++ b/gcc/tree-pretty-print.cc
@@ -3201,6 +3201,8 @@ dump_generic_node (pretty_printer *pp, tree node, int 
spc, dump_flags_t flags,
        pp_string (pp, " [return slot optimization]");
       if (CALL_EXPR_TAILCALL (node))
        pp_string (pp, " [tail call]");
+      if (CALL_EXPR_MUST_TAIL_CALL (node))
+       pp_string (pp, " [must tail call]");
       break;
 
     case WITH_CLEANUP_EXPR:

Reply via email to