This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[trunk,vta] fix -g/-g0 codegen difference in cxx_dwarf_name()


The fix for PR c++/14912, about two months ago, brought about an
-fcompare-debug regression.  cxx_dwarf_name(), only called when emitting
debug information, may end up getting the then-added
count_non_default_template_args().

This function performs template substitution in default template
arguments, to compare them with the actual arguments.  This substitution
may create new decls, getting decl uids out of sync.

In the testcase I looked at, -fcomopare-debug failed just because the
final RTL dumps contained the names of D.<uid> decls, but out-of-sync
UIDs are known to cause actual codegen differences, from other
-fcompare-debug fixes, so I'd like to install this fix.

Ok for trunk?

for  gcc/cp/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* cp-tree.h (TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS): New.
	* cp-lang.c (cxx_dwarf_name): Pass it.
	* error.c (count_non_default_template_args): Take flags as
	argument.  Adjust all callers.  Skip counting of default
	arguments if the new flag is given.

Index: gcc/cp/cp-lang.c
===================================================================
--- gcc/cp/cp-lang.c.orig	2009-03-01 02:15:51.000000000 -0300
+++ gcc/cp/cp-lang.c	2009-06-02 04:21:42.000000000 -0300
@@ -1,5 +1,5 @@
 /* Language-dependent hooks for C++.
-   Copyright 2001, 2002, 2004, 2007, 2008 Free Software Foundation, Inc.
+   Copyright 2001, 2002, 2004, 2007, 2008, 2009 Free Software Foundation, Inc.
    Contributed by Alexandre Oliva  <aoliva@redhat.com>
 
 This file is part of GCC.
@@ -110,7 +110,9 @@ cxx_dwarf_name (tree t, int verbosity)
   gcc_assert (DECL_P (t));
 
   if (verbosity >= 2)
-    return decl_as_string (t, TFF_DECL_SPECIFIERS | TFF_UNQUALIFIED_NAME);
+    return decl_as_string (t,
+			   TFF_DECL_SPECIFIERS | TFF_UNQUALIFIED_NAME
+			   | TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS);
 
   return cxx_printable_name (t, verbosity);
 }
Index: gcc/cp/cp-tree.h
===================================================================
--- gcc/cp/cp-tree.h.orig	2009-05-28 03:28:39.000000000 -0300
+++ gcc/cp/cp-tree.h	2009-06-02 04:21:10.000000000 -0300
@@ -3923,7 +3923,9 @@ enum overload_flags { NO_SPECIAL = 0, DT
    TFF_EXPR_IN_PARENS: parenthesize expressions.
    TFF_NO_FUNCTION_ARGUMENTS: don't show function arguments.
    TFF_UNQUALIFIED_NAME: do not print the qualifying scope of the
-       top-level entity.  */
+       top-level entity.
+   TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS: do not omit template arguments
+       identical to their defaults.  */
 
 #define TFF_PLAIN_IDENTIFIER			(0)
 #define TFF_SCOPE				(1)
@@ -3938,6 +3940,7 @@ enum overload_flags { NO_SPECIAL = 0, DT
 #define TFF_EXPR_IN_PARENS			(1 << 9)
 #define TFF_NO_FUNCTION_ARGUMENTS		(1 << 10)
 #define TFF_UNQUALIFIED_NAME			(1 << 11)
+#define TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS	(1 << 12)
 
 /* Returns the TEMPLATE_DECL associated to a TEMPLATE_TEMPLATE_PARM
    node.  */
Index: gcc/cp/error.c
===================================================================
--- gcc/cp/error.c.orig	2009-05-12 02:34:48.000000000 -0300
+++ gcc/cp/error.c	2009-06-02 04:26:25.000000000 -0300
@@ -84,7 +84,7 @@ static void dump_template_bindings (tree
 static void dump_scope (tree, int);
 static void dump_template_parms (tree, int, int);
 
-static int count_non_default_template_args (tree, tree);
+static int count_non_default_template_args (tree, tree, int);
 
 static const char *function_category (tree);
 static void maybe_print_instantiation_context (diagnostic_context *);
@@ -163,12 +163,19 @@ dump_template_argument (tree arg, int fl
    match the (optional) default template parameter in PARAMS  */
 
 static int
-count_non_default_template_args (tree args, tree params)
+count_non_default_template_args (tree args, tree params, int flags)
 {
   int n = TREE_VEC_LENGTH (args);
   int last;
 
-  if (params == NULL_TREE || !flag_pretty_templates)
+  if (params == NULL_TREE
+      /* We use this flag when generating debug information.  We don't
+	 want to expand templates at this point, for this may generate
+	 new decls, which gets decl counts out of sync, which may in
+	 turn cause codegen differences between compilations with and
+	 without -g.  */
+      || (flags & TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS) != 0
+      || !flag_pretty_templates)
     return n;
 
   for (last = n - 1; last >= 0; --last)
@@ -197,7 +204,7 @@ count_non_default_template_args (tree ar
 static void
 dump_template_argument_list (tree args, tree parms, int flags)
 {
-  int n = count_non_default_template_args (args, parms);
+  int n = count_non_default_template_args (args, parms, flags);
   int need_comma = 0;
   int i;
 
@@ -1446,7 +1453,7 @@ dump_template_parms (tree info, int prim
       if (TMPL_ARGS_HAVE_MULTIPLE_LEVELS (args))
 	args = TREE_VEC_ELT (args, TREE_VEC_LENGTH (args) - 1);
 
-      len = count_non_default_template_args (args, params);
+      len = count_non_default_template_args (args, params, flags);
 
       for (ix = 0; ix != len; ix++)
 	{
-- 
Alexandre Oliva, freedom fighter    http://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/   FSF Latin America board member
Free Software Evangelist      Red Hat Brazil Compiler Engineer

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]