Patchwork [pph] Merge fields and methods, etc. (issue5781061)

login
register
mail settings
Submitter Lawrence Crowl
Date March 8, 2012, 8:56 p.m.
Message ID <20120308205616.160B42226C4@jade.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/145627/
State New
Headers show

Comments

Lawrence Crowl - March 8, 2012, 8:56 p.m.
This patch provides three primary fixes.

* Merge structure fields and methods.

This merging is necessary because a field or method declaration may be
updated with a definition.

Tests x4keyed.cc, x4keyex.cc, and x4keyno.cc expose a problem with
callgraphs and are no longer passing.  Test x7rtti.cc exposes the same
problem, but it was not passing before.

Test x4incomplete4321.cc exposes a problem with gimple expansion, but
it was not passing before.

Test x4incomplete4123.cc newly fails emitting an unneeded function.

Tests x4tmplclass2.cc, z4tmplclass1.cc, and z4tmplclass2.cc newly pass.

* Distinguish template type parameters in error output.

The problem here is that the merge names were the same for different
types.  The change was to add the source location information as a
qualifier to the template parameter name in error pretty printing.
Control this with a TFF flag.

New tests x0dependent.h and x1dependent.cc pass.

* Remove gcc_assert in mangle.c added in the last patch.

We restore this assert mostly to reduce any future client merge
burden.

Test x6dynarray5.cc now fails differently


In addition there are some infrastructure changes.

* Add capability to add notes to the trace output.  This capability is
used to emit merge names into the trace.

* Add functions pph_out_struct_function_for_decl and
pph_out_cgraph_node_for_decl to provide a better debugging handle on
symtab expansion.



--
This patch is available for review at http://codereview.appspot.com/5781061

Patch

Index: gcc/testsuite/ChangeLog.pph

2012-03-07   Lawrence Crowl  <crowl@google.com>

	* g++.dg/pph/x0dependent.h: New.
	* g++.dg/pph/x1dependent.cc: New.
	* g++.dg/pph/x4incomplete4123.cc: Mark xdiff on extra function.
	* g++.dg/pph/x4incomplete4321.cc: Mark ICE on gimple.
	* g++.dg/pph/x4keyed.cc: Mark ICE on cgraph.
	* g++.dg/pph/x4keyex.cc: Mark ICE on cgraph.
	* g++.dg/pph/x4keyno.cc: Mark ICE on cgraph.
	* g++.dg/pph/x4tmplclass1.cc: Mark change in labels.
	* g++.dg/pph/x4tmplclass2.cc: Mark xokay.
	* g++.dg/pph/x6dynarray5.cc: Mark different ICE.
	* g++.dg/pph/x7rtti.cc: Mark ICE on cgraph.
	* g++.dg/pph/z4tmplclass1.cc: Mark xokay.
	* g++.dg/pph/z4tmplclass2.cc: Mark xokay.

Index: gcc/cp/ChangeLog.pph

2012-03-07   Lawrence Crowl  <crowl@google.com>

	* cp-tree.h (TFF_LOC_FOR_TEMPLATE_PARMS): New.
	* error.c (dump_location_qualifier): New.
	(dump_type): Add source location qualifier to template type parameter
	identifiers.
	* mangle.c (write_template_arg_literal): Revert to prior code.
	* pph-streamer.h (pph_trace_note): New.
	* pph-core.c (pph_trace_note): New.
	* pph-out.c (pph_out_struct_function_for_decl): New.
	(pph_out_cgraph_node_for_decl): New.
	(pph_out_symtab): Update to use functions above.
	(pph_merge_name): Add TFF_LOC_FOR_TEMPLATE_PARMS for pretty name.
	(pph_out_merge_name): Trace merge names.
	(pph_out_merge_key_tree): Emit merge keys for class fields and methods.
	* pph-in.c (pph_in_merge_key_tree_with_searcher): Merge in keys for
	class fields and methods.


Index: gcc/testsuite/g++.dg/pph/x4keyno.cc
===================================================================
--- gcc/testsuite/g++.dg/pph/x4keyno.cc	(revision 184901)
+++ gcc/testsuite/g++.dg/pph/x4keyno.cc	(working copy)
@@ -1,4 +1,7 @@ 
-// pph asm xokay 32642
+// { dg-xfail-if "ICE" { "*-*-*" } { "-fpph-map=pph.map" } }
+// { dg-bogus "x4keyno.cc:13:1: internal compiler error: in cgraph_analyze_functions, at cgraphunit.c:1210" "" { xfail *-*-* } 0 }
+
+// was asm xokay 32642
 
 #include "x0keyno1.h"
 #include "x0keyno2.h"
Index: gcc/testsuite/g++.dg/pph/x6dynarray5.h
===================================================================
--- gcc/testsuite/g++.dg/pph/x6dynarray5.h	(revision 184901)
+++ gcc/testsuite/g++.dg/pph/x6dynarray5.h	(working copy)
@@ -3,7 +3,7 @@ 
 // { dg-bogus "bits/allocator.h:153:12: sorry, unimplemented: mangling trait_expr" "" { xfail *-*-* } 0 }
 // { dg-bogus "bits/stl_construct.h:98:12: sorry, unimplemented: mangling trait_expr" "" { xfail *-*-* } 0 }
 // { dg-bogus "bits/stl_tempbuf.h:183:12: sorry, unimplemented: mangling trait_expr" "" { xfail *-*-* } 0 }
-// { dg-bogus "bits/cpp_type_traits.h:87:12: internal compiler error: in write_template_arg_literal, at cp/mangle.c:2919" "" { xfail *-*-* } 0 }
+// { dg-bogus "bits/cpp_type_traits.h:87:12: internal compiler error: tree check: expected integer_cst, have const_decl in tree_int_cst_sgn, at tree.c:6567" "" { xfail *-*-* } 0 }
 
 #ifndef X6DYNARRAY5_H
 #define X6DYNARRAY5_H
Index: gcc/testsuite/g++.dg/pph/x7rtti.cc
===================================================================
--- gcc/testsuite/g++.dg/pph/x7rtti.cc	(revision 184901)
+++ gcc/testsuite/g++.dg/pph/x7rtti.cc	(working copy)
@@ -1,7 +1,8 @@ 
-// {    xfail-if "UNKNOWN MACRO AND BOGUS RTTI" { "*-*-*" } { "-fpph-map=pph.map" } }
-// { dg-bogus "x7rtti.cc:9:0: warning: .__STDC_IEC_559_COMPLEX__. redefined" "" { xfail *-*-* } 0 }
-// { dg-bogus "x7rtti.cc:9:0: warning: .__STDC_ISO_10646__. redefined" "" { xfail *-*-* } 0 }
-// { dg-bogus "x7rtti.cc:9:0: warning: .__STDC_IEC_559__. redefined" "" { xfail *-*-* } 0 }
+// { dg-xfail-if "UNKNOWN MACRO AND BOGUS RTTI" { "*-*-*" } { "-fpph-map=pph.map" } }
+// { dg-bogus "x7rtti.cc:10:0: warning: .__STDC_IEC_559_COMPLEX__. redefined" "" { xfail *-*-* } 0 }
+// { dg-bogus "x7rtti.cc:10:0: warning: .__STDC_ISO_10646__. redefined" "" { xfail *-*-* } 0 }
+// { dg-bogus "x7rtti.cc:10:0: warning: .__STDC_IEC_559__. redefined" "" { xfail *-*-* } 0 }
+// { dg-bogus "x7rtti.cc:22:1: internal compiler error: in cgraph_analyze_functions, at cgraphunit.c:1210" "" { xfail *-*-* } 0 }
 // FIXME pph: This should be a { dg=do run } (with '=' replaced by '-')
 
 #include "x5rtti1.h"
Index: gcc/testsuite/g++.dg/pph/z4tmplclass1.cc
===================================================================
--- gcc/testsuite/g++.dg/pph/z4tmplclass1.cc	(revision 184901)
+++ gcc/testsuite/g++.dg/pph/z4tmplclass1.cc	(working copy)
@@ -1,5 +1,5 @@ 
-// pph asm xdiff 54665
-// xfail-if BOGUS DUPFUNC
+// pph asm xokay 15070
+// Label numbers are different.
 
 #include "x0tmplclass13.h"
 #include "x0tmplclass14.h"
Index: gcc/testsuite/g++.dg/pph/x4incomplete4123.cc
===================================================================
--- gcc/testsuite/g++.dg/pph/x4incomplete4123.cc	(revision 184901)
+++ gcc/testsuite/g++.dg/pph/x4incomplete4123.cc	(working copy)
@@ -1,3 +1,6 @@ 
+// pph asm xdiff 21766
+// xfail-if unneeded copy of copies::copies() emitted
+
 #include "x0incomplete1.h"
 #include "x0incomplete2.h"
 #include "x0incomplete3.h"
Index: gcc/testsuite/g++.dg/pph/x4keyex.cc
===================================================================
--- gcc/testsuite/g++.dg/pph/x4keyex.cc	(revision 184901)
+++ gcc/testsuite/g++.dg/pph/x4keyex.cc	(working copy)
@@ -1,4 +1,7 @@ 
-// pph asm xokay 32642
+// { dg-xfail-if "ICE" { "*-*-*" } { "-fpph-map=pph.map" } }
+// { dg-bogus "x4keyex.cc:28:1: internal compiler error: in cgraph_analyze_functions, at cgraphunit.c:1210" "" { xfail *-*-* } 0 }
+
+// formerly was asm xokay 32642
 //
 // This test case fails to compare because LFB/LFE labels are different.
 //
Index: gcc/testsuite/g++.dg/pph/z4tmplclass2.cc
===================================================================
--- gcc/testsuite/g++.dg/pph/z4tmplclass2.cc	(revision 184901)
+++ gcc/testsuite/g++.dg/pph/z4tmplclass2.cc	(working copy)
@@ -1,5 +1,5 @@ 
-// pph asm xdiff 44158
-// xfail-if BOGUS DUPVAR DUPFUNC
+// pph asm xokay 62353
+// Labels are different.  Two variable definitions have moved
 
 #include "x0tmplclass23.h"
 #include "x0tmplclass24.h"
Index: gcc/testsuite/g++.dg/pph/x1dependent.cc
===================================================================
--- gcc/testsuite/g++.dg/pph/x1dependent.cc	(revision 0)
+++ gcc/testsuite/g++.dg/pph/x1dependent.cc	(revision 0)
@@ -0,0 +1 @@ 
+#include "x0dependent.h"
Index: gcc/testsuite/g++.dg/pph/x4tmplclass1.cc
===================================================================
--- gcc/testsuite/g++.dg/pph/x4tmplclass1.cc	(revision 184901)
+++ gcc/testsuite/g++.dg/pph/x4tmplclass1.cc	(working copy)
@@ -1,4 +1,4 @@ 
-// pph asm xokay 03516
+// pph asm xokay 46519
 // Label numbers are different.
 
 #include "x0tmplclass11.h"
Index: gcc/testsuite/g++.dg/pph/x0dependent.h
===================================================================
--- gcc/testsuite/g++.dg/pph/x0dependent.h	(revision 0)
+++ gcc/testsuite/g++.dg/pph/x0dependent.h	(revision 0)
@@ -0,0 +1,27 @@ 
+#ifndef X0DEPENDENT_H
+#define X0DEPENDENT_H
+
+template<typename T>
+struct outer;
+
+template<>
+struct outer< void >
+{
+  template< typename U >
+  struct inner
+  {
+    typedef outer<U> other;
+  };
+};
+
+template< typename T >
+struct outer
+{
+  template< typename U >
+  struct inner
+  {
+    typedef outer<U> other;
+  };
+};
+
+#endif
Index: gcc/testsuite/g++.dg/pph/x4keyed.cc
===================================================================
--- gcc/testsuite/g++.dg/pph/x4keyed.cc	(revision 184901)
+++ gcc/testsuite/g++.dg/pph/x4keyed.cc	(working copy)
@@ -1,4 +1,5 @@ 
-// pph asm xokay 27667
+// { dg-xfail-if "ICE" { "*-*-*" } { "-fpph-map=pph.map" } }
+// { dg-bogus "x4keyed.cc:13:1: internal compiler error: in cgraph_analyze_functions, at cgraphunit.c:1210" "" { xfail *-*-* } 0 }
 
 #include "x0keyed1.h"
 #include "x0keyed2.h"
Index: gcc/testsuite/g++.dg/pph/x4incomplete4321.cc
===================================================================
--- gcc/testsuite/g++.dg/pph/x4incomplete4321.cc	(revision 184901)
+++ gcc/testsuite/g++.dg/pph/x4incomplete4321.cc	(working copy)
@@ -1,6 +1,5 @@ 
-// pph asm xdiff 64351
-// xfail-if BOGUS MISSFUN
-// missing constructors
+// { dg-xfail-if "ICE" { "*-*-*" } { "-fpph-map=pph.map" } }
+// { dg-bogus "a0incomplete2.hi:7:5: internal compiler error: in gimple_expand_cfg, at cfgexpand.c:4454" "" { xfail *-*-* } 0 }
 
 #include "x0incomplete3.h"
 #include "x0incomplete2.h"
Index: gcc/testsuite/g++.dg/pph/x4tmplclass2.cc
===================================================================
--- gcc/testsuite/g++.dg/pph/x4tmplclass2.cc	(revision 184901)
+++ gcc/testsuite/g++.dg/pph/x4tmplclass2.cc	(working copy)
@@ -1,5 +1,5 @@ 
-// pph asm xdiff 51443
-// xfail-if BOGUS DUPFUNC
+// pph asm xokay 52506
+// Label numbers are different.
 
 #include "x0tmplclass21.h"
 #include "x0tmplclass22.h"
Index: gcc/cp/pph-core.c
===================================================================
--- gcc/cp/pph-core.c	(revision 184901)
+++ gcc/cp/pph-core.c	(working copy)
@@ -445,6 +445,16 @@  pph_trace_tree (tree t, const char *name
 }
 
 
+/* Print a note into the tracing stream.  */
+
+void
+pph_trace_note (const char *type, const char *value)
+{
+  if ( flag_pph_tracer >= 3 )
+    fprintf (pph_logfile, "PPH: %s: %s\n", type, value);
+}
+
+
 /************************************************* pph pointer mapping cache */
 
 
Index: gcc/cp/error.c
===================================================================
--- gcc/cp/error.c	(revision 184901)
+++ gcc/cp/error.c	(working copy)
@@ -350,6 +350,25 @@  dump_alias_template_specialization (tree
 		       flags & ~TFF_TEMPLATE_HEADER);
 }
 
+
+/* Dump a location of a DECL as a qualifier, depending on FLAGS.  */
+
+static void
+dump_location_qualifier (tree decl, int flags)
+{
+if (flags & TFF_LOC_FOR_TEMPLATE_PARMS)
+  {
+    expanded_location xloc = expand_location (DECL_SOURCE_LOCATION (decl));
+    char *buffer = (char*)xmalloc (strlen (xloc.file) + 46);
+    if (xloc.column != 0)
+      sprintf (buffer, "`%s:%d:%d`", xloc.file, xloc.line, xloc.column);
+    else
+      sprintf (buffer, "`%s:%d`", xloc.file, xloc.line);
+    pp_cxx_ws_string (cxx_pp, buffer);
+    free (buffer);
+  }
+}
+
 /* Dump a human-readable equivalent of TYPE.  FLAGS controls the
    format.  */
 
@@ -466,6 +485,7 @@  dump_type (tree t, int flags)
       {
 	tree decl = TYPE_NAME (t);
 	pp_cxx_cv_qualifier_seq (cxx_pp, t);
+	dump_location_qualifier (decl, flags);
 	if (decl)
 	  {
 	    tree ident = DECL_NAME (decl);
Index: gcc/cp/pph-out.c
===================================================================
--- gcc/cp/pph-out.c	(revision 184901)
+++ gcc/cp/pph-out.c	(working copy)
@@ -1477,6 +1477,15 @@  pph_out_struct_function (pph_stream *str
 }
 
 
+/* Write the struct function instance for DECL to STREAM.  */
+
+static void
+pph_out_struct_function_for_decl (pph_stream *stream, tree decl)
+{
+  pph_out_struct_function (stream, DECL_STRUCT_FUNCTION (decl));
+}
+
+
 /* Write all the fields in lang_decl_base instance LDB to OB.  */
 
 static void
@@ -1796,6 +1805,7 @@  pph_out_lang_type (pph_stream *stream, t
     pph_out_lang_type_ptrmem (stream, &lt->u.ptrmem);
 }
 
+
 /* Write machine_mode value MODE to STREAM.  */
 
 static void
@@ -2160,7 +2170,8 @@  pph_merge_name (tree expr)
 		   | TFF_SCOPE
 		   | TFF_DECL_SPECIFIERS
 		   | TFF_CLASS_KEY_OR_ENUM
-		   | TFF_RETURN_TYPE;
+		   | TFF_RETURN_TYPE
+		   | TFF_LOC_FOR_TEMPLATE_PARMS;
 
   if (TYPE_P (expr))
     expr = TYPE_NAME (expr);
@@ -2202,6 +2213,7 @@  static void
 pph_out_merge_name (pph_stream *stream, tree expr)
 {
   char *name = pph_merge_name (expr);
+  pph_trace_note ("merge name", name);
   pph_out_string (stream, name);
   free (name);
 }
@@ -2299,7 +2311,12 @@  pph_out_merge_key_tree (pph_stream *stre
     {
       if (name_type)
 	pph_out_merge_name (stream, expr);
-      gcc_assert (TYPE_P (expr));
+      if (CLASS_TYPE_P (expr))
+	{
+	  unsigned filter = PPHF_NO_XREFS | PPHF_NO_PREFS | PPHF_NO_BUILTINS;
+	  pph_out_merge_key_chain (stream, TYPE_FIELDS (expr), filter);
+	  pph_out_merge_key_chain (stream, TYPE_METHODS (expr), filter);
+	}
     }
 
   if (flag_pph_tracer)
@@ -2463,6 +2480,14 @@  pph_out_cgraph_node (pph_stream *stream,
   pph_out_bitpack (stream, &bp);
 }
 
+/* Emit callgraph for DECL to STREAM.  */
+
+static void
+pph_out_cgraph_node_for_decl (pph_stream *stream, tree decl)
+{
+  pph_out_cgraph_node (stream, cgraph_get_node (decl));
+}
+
 
 /* Add DECL to the symbol table for pph_out_stream.  ACTION determines
    how DECL should be presented to the middle-end when reading this
@@ -2516,8 +2541,8 @@  pph_out_symtab (pph_stream *stream)
 	}
       else if (entry->action == PPH_SYMTAB_EXPAND)
 	{
-	  pph_out_struct_function (stream, DECL_STRUCT_FUNCTION (entry->decl));
-	  pph_out_cgraph_node (stream, cgraph_get_node (entry->decl));
+	  pph_out_struct_function_for_decl (stream, entry->decl);
+	  pph_out_cgraph_node_for_decl (stream, entry->decl);
 	}
       else
 	gcc_unreachable ();
Index: gcc/cp/pph-streamer.h
===================================================================
--- gcc/cp/pph-streamer.h	(revision 184901)
+++ gcc/cp/pph-streamer.h	(working copy)
@@ -262,6 +262,7 @@  void pph_stream_close_no_flush (pph_stre
 void pph_trace_marker (enum pph_record_marker marker, enum pph_tag tag);
 void pph_trace_tree (tree, const char *,
 		     enum pph_trace_end, enum pph_trace_kind);
+void pph_trace_note (const char *kind, const char *value);
 pph_cache_entry *pph_cache_insert_at (pph_cache *, void *, unsigned,
 				      enum pph_tag);
 pph_cache_entry *pph_cache_lookup (pph_cache *, void *, unsigned *,
Index: gcc/cp/mangle.c
===================================================================
--- gcc/cp/mangle.c	(revision 184901)
+++ gcc/cp/mangle.c	(working copy)
@@ -2914,11 +2914,7 @@  write_template_arg_literal (const tree v
     switch (TREE_CODE (value))
       {
       case CONST_DECL:
-	{
-	  tree initial = DECL_INITIAL (value);
-	  gcc_assert (TREE_CODE (initial) == INTEGER_CST);
-	  write_integer_cst (value);
-	}
+	write_integer_cst (value);
 	break;
 
       case INTEGER_CST:
Index: gcc/cp/cp-tree.h
===================================================================
--- gcc/cp/cp-tree.h	(revision 184901)
+++ gcc/cp/cp-tree.h	(working copy)
@@ -4560,7 +4560,8 @@  enum overload_flags { NO_SPECIAL = 0, DT
    TFF_UNQUALIFIED_NAME: do not print the qualifying scope of the
        top-level entity.
    TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS: do not omit template arguments
-       identical to their defaults.  */
+       identical to their defaults.
+   TFF_LOC_FOR_TEMPLATE_PARMS: add a location modifier to template parms.  */
 
 #define TFF_PLAIN_IDENTIFIER			(0)
 #define TFF_SCOPE				(1)
@@ -4576,6 +4577,7 @@  enum overload_flags { NO_SPECIAL = 0, DT
 #define TFF_NO_FUNCTION_ARGUMENTS		(1 << 10)
 #define TFF_UNQUALIFIED_NAME			(1 << 11)
 #define TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS	(1 << 12)
+#define TFF_LOC_FOR_TEMPLATE_PARMS		(1 << 13)
 
 /* Returns the TEMPLATE_DECL associated to a TEMPLATE_TEMPLATE_PARM
    node.  */
Index: gcc/cp/pph-in.c
===================================================================
--- gcc/cp/pph-in.c	(revision 184901)
+++ gcc/cp/pph-in.c	(working copy)
@@ -2589,6 +2589,11 @@  pph_in_merge_key_tree_with_searcher (pph
     }
   else
     {
+      if (CLASS_TYPE_P (expr))
+	{
+	  pph_in_merge_key_chain (stream, &TYPE_FIELDS (expr));
+	  pph_in_merge_key_chain (stream, &TYPE_METHODS (expr));
+	}
     }
 
   if (flag_pph_tracer)