Re: [PATCH] Avoid dumping fancy names in -fcompare-debug dumps (PR c++/84704)

2018-03-06 Thread Jeff Law
On 03/06/2018 01:47 PM, Jakub Jelinek wrote:
> Hi!
> 
> As discussed, e.g. gimplification of STATEMENT_LISTs can create extra
> retval.N temporaries for -g and get the counts out of sync, similarly
> the SAVE_EXPR change proposed in the fix for that PR could for decls
> in the statement expressions or addresses thereof get the fancy names
> counters out of sync.
> 
> The following patch marks the temporaries DECL_NAMELESS in addition to
> DECL_IGNORED_P and in the dumps used for -fcompare-debug checking
> prints those as D. rather than retval.234.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> 
> 2018-03-06  Jakub Jelinek  
> 
>   PR c++/84704
>   * gimple-expr.c (create_tmp_var_raw): Set DECL_NAMELESS flag
>   on tmp_var.
>   * tree-pretty-print.c (dump_decl_name): For TDF_COMPARE_DEBUG,
>   don't print names of DECL_NAMELESS DECL_IGNORED_P decls.
OK.
jeff


[PATCH] Avoid dumping fancy names in -fcompare-debug dumps (PR c++/84704)

2018-03-06 Thread Jakub Jelinek
Hi!

As discussed, e.g. gimplification of STATEMENT_LISTs can create extra
retval.N temporaries for -g and get the counts out of sync, similarly
the SAVE_EXPR change proposed in the fix for that PR could for decls
in the statement expressions or addresses thereof get the fancy names
counters out of sync.

The following patch marks the temporaries DECL_NAMELESS in addition to
DECL_IGNORED_P and in the dumps used for -fcompare-debug checking
prints those as D. rather than retval.234.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2018-03-06  Jakub Jelinek  

PR c++/84704
* gimple-expr.c (create_tmp_var_raw): Set DECL_NAMELESS flag
on tmp_var.
* tree-pretty-print.c (dump_decl_name): For TDF_COMPARE_DEBUG,
don't print names of DECL_NAMELESS DECL_IGNORED_P decls.

--- gcc/gimple-expr.c.jj2018-01-14 17:16:55.693836137 +0100
+++ gcc/gimple-expr.c   2018-03-06 09:02:08.268188451 +0100
@@ -446,6 +446,9 @@ create_tmp_var_raw (tree type, const cha
   DECL_ARTIFICIAL (tmp_var) = 1;
   /* And we don't want debug info for it.  */
   DECL_IGNORED_P (tmp_var) = 1;
+  /* And we don't want even the fancy names of those printed in
+ -fdump-final-insns= dumps.  */
+  DECL_NAMELESS (tmp_var) = 1;
 
   /* Make the variable writable.  */
   TREE_READONLY (tmp_var) = 0;
--- gcc/tree-pretty-print.c.jj  2018-01-31 21:38:08.005050021 +0100
+++ gcc/tree-pretty-print.c 2018-03-06 09:13:08.026095230 +0100
@@ -247,21 +247,32 @@ dump_fancy_name (pretty_printer *pp, tre
 static void
 dump_decl_name (pretty_printer *pp, tree node, dump_flags_t flags)
 {
-  if (DECL_NAME (node))
+  tree name = DECL_NAME (node);
+  if (name)
 {
   if ((flags & TDF_ASMNAME)
  && HAS_DECL_ASSEMBLER_NAME_P (node)
  && DECL_ASSEMBLER_NAME_SET_P (node))
pp_tree_identifier (pp, DECL_ASSEMBLER_NAME_RAW (node));
+  /* For -fcompare-debug don't dump DECL_NAMELESS names at all,
+-g might have created more fancy names and their indexes
+could get out of sync.  Usually those should be DECL_IGNORED_P
+too, SRA can create even non-DECL_IGNORED_P DECL_NAMELESS fancy
+names, let's hope those never get out of sync after doing the
+dump_fancy_name sanitization.  */
+  else if ((flags & TDF_COMPARE_DEBUG)
+  && DECL_NAMELESS (node)
+  && DECL_IGNORED_P (node))
+   name = NULL_TREE;
   /* For DECL_NAMELESS names look for embedded uids in the
 names and sanitize them for TDF_NOUID.  */
   else if ((flags & TDF_NOUID) && DECL_NAMELESS (node))
-   dump_fancy_name (pp, DECL_NAME (node));
+   dump_fancy_name (pp, name);
   else
-   pp_tree_identifier (pp, DECL_NAME (node));
+   pp_tree_identifier (pp, name);
 }
   char uid_sep = (flags & TDF_GIMPLE) ? '_' : '.';
-  if ((flags & TDF_UID) || DECL_NAME (node) == NULL_TREE)
+  if ((flags & TDF_UID) || name == NULL_TREE)
 {
   if (TREE_CODE (node) == LABEL_DECL && LABEL_DECL_UID (node) != -1)
pp_printf (pp, "L%c%d", uid_sep, (int) LABEL_DECL_UID (node));

Jakub