https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121045

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #15 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
If discriminators don't really affect code generation nor emitted assembly
except for debug info, then guess yes, we might consider ignoring them for
-fcompare-debug.
But -fcompare-debug works by -fdump-final-insns= into 2 separate files and
comparing them.  So, to achieve that we'd need to avoid printing discriminators
for TDF_COMPARE_DEBUG.

Thus, following patch fixes the testsuite regressions:

2026-01-14  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.

--- gcc/tree-pretty-print.h.jj  2026-01-02 09:56:10.384332850 +0100
+++ gcc/tree-pretty-print.h     2026-01-14 16:21:33.915234660 +0100
@@ -56,6 +56,7 @@ extern void print_call_name (pretty_prin
 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 */
--- gcc/tree-pretty-print.cc.jj 2026-01-02 09:56:10.384332850 +0100
+++ gcc/tree-pretty-print.cc    2026-01-14 16:21:49.730968237 +0100
@@ -1780,7 +1780,7 @@ print_omp_context_selector (FILE *file,
 /* 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, locat
   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, tre
     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, t
     }

   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)
--- gcc/gimple-pretty-print.cc.jj       2026-01-09 21:59:08.707543800 +0100
+++ gcc/gimple-pretty-print.cc  2026-01-14 16:23:03.683722458 +0100
@@ -2470,7 +2470,7 @@ dump_gimple_phi (pretty_printer *pp, con
   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, co
     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,

       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 (diag

        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);
--- gcc/print-rtl.cc.jj 2026-01-09 21:59:08.709543767 +0100
+++ gcc/print-rtl.cc    2026-01-14 16:25:11.661566606 +0100
@@ -458,10 +458,9 @@ rtx_writer::print_rtx_operand_code_L (co
          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
     }

Reply via email to