> Am 15.01.2026 um 07:59 schrieb Jakub Jelinek <[email protected]>:
> 
> Hi!
> 
> 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).
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

Ok

Richard 

> 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.
> 
> --- 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
>     }
> 
>    Jakub
> 

Reply via email to