]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
compare-debug: Don't print discriminators for -fdump-final-insns= [PR121045]
authorJakub Jelinek <jakub@redhat.com>
Thu, 15 Jan 2026 11:03:34 +0000 (12:03 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 15 Jan 2026 11:03:34 +0000 (12:03 +0100)
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  <jakub@redhat.com>

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/gimple-pretty-print.cc
gcc/print-rtl.cc
gcc/tree-pretty-print.cc
gcc/tree-pretty-print.h

index 4b27b97017366aa79864e35b0f429288c6fcaff3..4b88d542a1dd97f61111bee1e42f792c468ca713 100644 (file)
@@ -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);
index 976a060be7f82280de8185e48a7c26532a93f7f5..56a3f52895f250e4c4dd8aebe6fe52d0f8695806 100644 (file)
@@ -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
     }
index 84f58873fe082f0ea6a227c441229b386d17924f..ca1a6f2f4704fd682e6173044b9bd0a80bbb3a4b 100644 (file)
@@ -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)
index 36d8e8dd523774161dcaed7e2a011cbf1c3d9ac5..78057b1153545eb1814322a5cde6cbdff90b8f23 100644 (file)
@@ -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 */