https://gcc.gnu.org/g:e4f3fc66841af8206177d5dabb40caccfea3dc2f

commit r16-6802-ge4f3fc66841af8206177d5dabb40caccfea3dc2f
Author: Jakub Jelinek <[email protected]>
Date:   Thu Jan 15 12:03:34 2026 +0100

    compare-debug: Don't print discriminators for -fdump-final-insns= [PR121045]
    
    Given the discussions in the PR, seems it is intentional that debug
    stmts are taken into account when assigning discriminators which is
    something that is actually never emitted into generated code, only
    into debug info, so for -g0 we might as well not try to compute them
    at all.
    
    But discriminators are printed in the dumps, including -fdump-final-insns=
    dump which affect -fcompare-debug.
    
    So, the following patch arranges not to print discriminators in that
    dump (i.e. when TDF_COMPARE_DEBUG is set in flags).
    
    I think we should also (but it can be handled incrementally) add
    some new TDF_* flag and -fdump-{tree,rtl,ipa}-<pass> modifier which
    will also disable printing discriminators (similar to nouid/TDF_NOUID)
    so that people can use it e.g. in -fcompare-debug -fdump-tree-all-nodiscrim
    and don't have to ignore discrim N changes in the dumps.
    
    This patch fixes
    -FAIL: c-c++-common/torture/pr116156-1.c   -O1  (test for excess errors)
    -FAIL: c-c++-common/torture/pr116156-1.c   -O2  (test for excess errors)
    -FAIL: c-c++-common/torture/pr116156-1.c   -O2 -flto -fno-use-linker-plugin 
-flto-partition=none  (test for excess errors)
    -FAIL: c-c++-common/torture/pr116156-1.c   -O3 -fomit-frame-pointer 
-funroll-loops -fpeel-loops -ftracer -finline-functions  (test for excess 
errors)
    -FAIL: c-c++-common/torture/pr116156-1.c   -O3 -g  (test for excess errors)
    -FAIL: c-c++-common/torture/pr116156-1.c   -Os  (test for excess errors)
    -FAIL: g++.dg/torture/pr58552.C   -O1  (test for excess errors)
    -FAIL: g++.dg/torture/pr58552.C   -O2  (test for excess errors)
    -FAIL: g++.dg/torture/pr58552.C   -O2 -flto -fno-use-linker-plugin 
-flto-partition=none  (test for excess errors)
    -FAIL: g++.dg/torture/pr58552.C   -O3 -g  (test for excess errors)
    -FAIL: g++.dg/torture/pr58552.C   -Os  (test for excess errors)
    so no testcase added for it.
    
    2026-01-15  Jakub Jelinek  <[email protected]>
    
            PR debug/121045
            * tree-pretty-print.h (dump_location): Add new dump_flags_t
            argument defaulted to TDF_NONE.
            * tree-pretty-print.cc (dump_location): Add flags argument.  Don't
            print discriminator if TDF_COMPARE_DEBUG bit is set in flags.
            (dump_block_node, dump_generic_node): Pass through flags to
            dump_location.
            * gimple-pretty-print.cc (dump_gimple_phi, pp_gimple_stmt_1,
            dump_implicit_edges): Likewise.
            (gimple_dump_bb_as_sarif_properties): Pass dump_flags to
            dump_location.
            * print-rtl.cc (rtx_writer::print_rtx_operand_code_L): If dump_flags
            has TDF_COMPARE_DEBUG bit set, don't print discriminators.

Diff:
---
 gcc/gimple-pretty-print.cc | 8 ++++----
 gcc/print-rtl.cc           | 5 ++---
 gcc/tree-pretty-print.cc   | 8 ++++----
 gcc/tree-pretty-print.h    | 3 ++-
 4 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/gcc/gimple-pretty-print.cc b/gcc/gimple-pretty-print.cc
index 4b27b9701736..4b88d542a1dd 100644
--- a/gcc/gimple-pretty-print.cc
+++ b/gcc/gimple-pretty-print.cc
@@ -2470,7 +2470,7 @@ dump_gimple_phi (pretty_printer *pp, const gphi *phi, int 
spc, bool comment,
   for (i = 0; i < gimple_phi_num_args (phi); i++)
     {
       if ((flags & TDF_LINENO) && gimple_phi_arg_has_location (phi, i))
-       dump_location (pp, gimple_phi_arg_location (phi, i));
+       dump_location (pp, gimple_phi_arg_location (phi, i), flags);
       basic_block src = gimple_phi_arg_edge (phi, i)->src;
       if (flags & TDF_GIMPLE)
        {
@@ -2724,7 +2724,7 @@ pp_gimple_stmt_1 (pretty_printer *pp, const gimple *gs, 
int spc,
     pp_printf (pp, "<&%p> ", (const void *) gs);
 
   if ((flags & TDF_LINENO) && gimple_has_location (gs))
-    dump_location (pp, gimple_location (gs));
+    dump_location (pp, gimple_location (gs), flags);
 
   if (flags & TDF_EH)
     {
@@ -3104,7 +3104,7 @@ dump_implicit_edges (pretty_printer *pp, basic_block bb, 
int indent,
 
       if ((flags & TDF_LINENO)
          && e->goto_locus != UNKNOWN_LOCATION)
-       dump_location (pp, e->goto_locus);
+       dump_location (pp, e->goto_locus, flags);
 
       pp_cfg_jump (pp, e, flags);
       pp_newline (pp);
@@ -3276,7 +3276,7 @@ gimple_dump_bb_as_sarif_properties 
(diagnostics::sarif_builder *,
 
        if ((dump_flags & TDF_LINENO)
            && e->goto_locus != UNKNOWN_LOCATION)
-         dump_location (pp, e->goto_locus);
+         dump_location (pp, e->goto_locus, dump_flags);
 
        pp_cfg_jump (pp, e, dump_flags);
        pp_newline (pp);
diff --git a/gcc/print-rtl.cc b/gcc/print-rtl.cc
index 976a060be7f8..56a3f52895f2 100644
--- a/gcc/print-rtl.cc
+++ b/gcc/print-rtl.cc
@@ -458,10 +458,9 @@ rtx_writer::print_rtx_operand_code_L (const_rtx in_rtx, 
int idx)
          expanded_location xloc = insn_location (in_insn);
          fprintf (m_outfile, " \"%s\":%i:%i", xloc.file, xloc.line,
                   xloc.column);
-         int discriminator = insn_discriminator (in_insn);
-           if (discriminator)
+         if ((dump_flags & TDF_COMPARE_DEBUG) == 0)
+           if (int discriminator = insn_discriminator (in_insn))
              fprintf (m_outfile, " discrim %d", discriminator);
-
        }
 #endif
     }
diff --git a/gcc/tree-pretty-print.cc b/gcc/tree-pretty-print.cc
index 84f58873fe08..ca1a6f2f4704 100644
--- a/gcc/tree-pretty-print.cc
+++ b/gcc/tree-pretty-print.cc
@@ -1780,7 +1780,7 @@ print_omp_context_selector (FILE *file, tree t, 
dump_flags_t flags)
 /* Dump location LOC to PP.  */
 
 void
-dump_location (pretty_printer *pp, location_t loc)
+dump_location (pretty_printer *pp, location_t loc, dump_flags_t flags)
 {
   expanded_location xloc = expand_location (loc);
   int discriminator = get_discriminator_from_loc (loc);
@@ -1794,7 +1794,7 @@ dump_location (pretty_printer *pp, location_t loc)
   pp_decimal_int (pp, xloc.line);
   pp_colon (pp);
   pp_decimal_int (pp, xloc.column);
-  if (discriminator)
+  if (discriminator && (flags & TDF_COMPARE_DEBUG) == 0)
   {
     pp_string (pp, " discrim ");
     pp_decimal_int (pp, discriminator);
@@ -1829,7 +1829,7 @@ dump_block_node (pretty_printer *pp, tree block, int spc, 
dump_flags_t flags)
     return;
 
   if (BLOCK_SOURCE_LOCATION (block))
-    dump_location (pp, BLOCK_SOURCE_LOCATION (block));
+    dump_location (pp, BLOCK_SOURCE_LOCATION (block), flags);
 
   newline_and_indent (pp, spc + 2);
 
@@ -2191,7 +2191,7 @@ dump_generic_node (pretty_printer *pp, tree node, int 
spc, dump_flags_t flags,
     }
 
   if ((flags & TDF_LINENO) && EXPR_HAS_LOCATION (node))
-    dump_location (pp, EXPR_LOCATION (node));
+    dump_location (pp, EXPR_LOCATION (node), flags);
 
   code = TREE_CODE (node);
   switch (code)
diff --git a/gcc/tree-pretty-print.h b/gcc/tree-pretty-print.h
index 36d8e8dd5237..78057b115354 100644
--- a/gcc/tree-pretty-print.h
+++ b/gcc/tree-pretty-print.h
@@ -56,6 +56,7 @@ extern void print_call_name (pretty_printer *, tree, 
dump_flags_t);
 extern void pp_tree_identifier (pretty_printer *, tree);
 extern void dump_function_header (FILE *, tree, dump_flags_t);
 extern void pp_double_int (pretty_printer *pp, double_int d, bool uns);
-extern void dump_location (pretty_printer *pp, location_t loc);
+extern void dump_location (pretty_printer *pp, location_t loc,
+                          dump_flags_t = TDF_NONE);
 
 #endif /* ! GCC_TREE_PRETTY_PRINT_H */

Reply via email to