PATCH: PR 42748

Mark Mitchell mitchell@codesourcery.com
Sat Feb 27 21:36:00 GMT 2010


PR 42748 is a problem about a mangling warning issued on ARM systems.
Because the source location at the point of the warning check
corresponds to the point at which we are doing the mangling, rather
than the point of the declaration whose name is being managled, we
cannot accurately tell whether we are mangling something from a system
header.  Thus, we give spurious warnings.

This patch makes the mangler set the source location to the location
of the declaration while doing the mangling.  I also made it push a
template instantiation level in the case that the manglee is a
template, so that we get the usual template instantiation backtrace in
that case.

Jason, do you see any problems with this?  If nobody objects, I'll
apply this in day or two.

--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713

2010-02-27  Mark Mitchell  <mark@codesourcery.com>

	PR c++/42748
	* cp-tree.h (push_tinst_level): Declare.
	(pop_tinst_level): Likewise.
	* pt.c (push_tinst_level): Give it external linkage.
	(pop_tinst_level): Likewise.
	* mangle.c (mangle_decl_string): Set the source location to that
	of the decl while mangling.

2010-02-27  Mark Mitchell  <mark@codesourcery.com>

	PR c++/42748
	* g++.dg/abi/mangle11.C: Adjust mangling warning locations.
	* g++.dg/abi/mangle12.C: Likewise.
	* g++.dg/abi/mangle20-2.C: Likewise.
	* g++.dg/abi/mangle17.C: Likewise.
	* g++.dg/template/cond2.C: Likewise.
	* g++.dg/template/pr35240.C: Likewise.

Index: gcc/cp/pt.c
===================================================================
--- gcc/cp/pt.c	(revision 157050)
+++ gcc/cp/pt.c	(working copy)
@@ -119,8 +119,6 @@ static int try_one_overload (tree, tree,
 			     unification_kind_t, int, bool);
 static int unify (tree, tree, tree, tree, int);
 static void add_pending_template (tree);
-static int push_tinst_level (tree);
-static void pop_tinst_level (void);
 static tree reopen_tinst_level (struct tinst_level *);
 static tree tsubst_initializer_list (tree, tree);
 static tree get_class_bindings (tree, tree, tree);
@@ -7011,7 +7009,7 @@ static int last_template_error_tick;
 /* We're starting to instantiate D; record the template instantiation context
    for diagnostics and to restore it later.  */
 
-static int
+int
 push_tinst_level (tree d)
 {
   struct tinst_level *new_level;
@@ -7054,7 +7052,7 @@ push_tinst_level (tree d)
 /* We're done instantiating this template; return to the instantiation
    context.  */
 
-static void
+void
 pop_tinst_level (void)
 {
   /* Restore the filename and line number stashed away when we started
Index: gcc/cp/mangle.c
===================================================================
--- gcc/cp/mangle.c	(revision 157050)
+++ gcc/cp/mangle.c	(working copy)
@@ -3005,6 +3005,22 @@ static tree
 mangle_decl_string (const tree decl)
 {
   tree result;
+  location_t saved_loc = input_location;
+  tree saved_fn = NULL_TREE;
+  bool template_p = false;
+
+  if (DECL_LANG_SPECIFIC (decl) && DECL_USE_TEMPLATE (decl))
+    {
+      struct tinst_level *tl = current_instantiation ();
+      if (!tl || tl->decl != decl)
+	{
+	  template_p = true;
+	  saved_fn = current_function_decl;
+	  push_tinst_level (decl);
+	  current_function_decl = NULL_TREE;
+	}
+    }
+  input_location = DECL_SOURCE_LOCATION (decl);
 
   start_mangling (decl);
 
@@ -3017,6 +3033,14 @@ mangle_decl_string (const tree decl)
   if (DEBUG_MANGLE)
     fprintf (stderr, "mangle_decl_string = '%s'\n\n",
 	     IDENTIFIER_POINTER (result));
+
+  if (template_p)
+    {
+      pop_tinst_level ();
+      current_function_decl = saved_fn;
+    }
+  input_location = saved_loc;
+
   return result;
 }
 
Index: gcc/cp/cp-tree.h
===================================================================
--- gcc/cp/cp-tree.h	(revision 157050)
+++ gcc/cp/cp-tree.h	(working copy)
@@ -4965,6 +4965,8 @@ extern void make_args_non_dependent		(VE
 extern bool reregister_specialization		(tree, tree, tree);
 extern tree fold_non_dependent_expr		(tree);
 extern bool explicit_class_specialization_p     (tree);
+extern int push_tinst_level                     (tree);
+extern void pop_tinst_level                     (void);
 extern struct tinst_level *outermost_tinst_level(void);
 extern bool parameter_of_template_p		(tree, tree);
 extern void init_template_processing		(void);
Index: gcc/testsuite/g++.dg/abi/mangle12.C
===================================================================
--- gcc/testsuite/g++.dg/abi/mangle12.C	(revision 157050)
+++ gcc/testsuite/g++.dg/abi/mangle12.C	(working copy)
@@ -1,11 +1,11 @@
 // { dg-options "-Wabi -fabi-version=1" }
 
 template <template <typename> class Q>
-void f (typename Q<int>::X) {}
+void f (typename Q<int>::X) {} // { dg-warning "mangle" }
 
 template <typename Q>
 struct S {
   typedef int X;
 };
 
-template void f<S> (int);  // { dg-warning "mangle" }
+template void f<S> (int);  // { dg-message "instantiated" }
Index: gcc/testsuite/g++.dg/abi/mangle20-2.C
===================================================================
--- gcc/testsuite/g++.dg/abi/mangle20-2.C	(revision 157050)
+++ gcc/testsuite/g++.dg/abi/mangle20-2.C	(working copy)
@@ -7,10 +7,10 @@
 // PR 9043
 // mangled array types in templates
 
-template <int I> void f(int (*)[2]) {}
+template <int I> void f(int (*)[2]) {} // { dg-warning "mangled name" }
 template <int I> void g(int (*)[I+2]) {}
 
-template void f<1>(int (*)[2]);  // { dg-warning "mangled name" }
+template void f<1>(int (*)[2]);  // { dg-message "instantiated" }
 //  { dg-final { scan-assembler "\n_?_Z1fILi1EEvPALi2E_i\[: \t\n\]" } }
 template void g<1>(int (*)[3]);
 //  { dg-final { scan-assembler "\n_?_Z1gILi1EEvPAplT_Li2E_i\[: \t\n\]" } }
Index: gcc/testsuite/g++.dg/abi/mangle17.C
===================================================================
--- gcc/testsuite/g++.dg/abi/mangle17.C	(revision 157050)
+++ gcc/testsuite/g++.dg/abi/mangle17.C	(working copy)
@@ -4,8 +4,8 @@ enum E { e = 3 };
 
 template <int I> struct S {};
 
-template <int I> void f (S<I + e + int (3.7)>) {}
-template void f<7>(S<7 + e + int (3.7)>); // { dg-warning "mangle" }
+template <int I> void f (S<I + e + int (3.7)>) {} // { dg-warning "mangle" }
+template void f<7>(S<7 + e + int (3.7)>); // { dg-message "instantiated" }
 
-template <int I> void g (S<I + e + int (3.7)>) {}
-template void g<7>(S<7 + e + int (3.7)>); // { dg-warning "mangle" }
+template <int I> void g (S<I + e + int (3.7)>) {} // { dg-warning "mangle" }
+template void g<7>(S<7 + e + int (3.7)>); // { dg-message "instantiated" }
Index: gcc/testsuite/g++.dg/abi/mangle11.C
===================================================================
--- gcc/testsuite/g++.dg/abi/mangle11.C	(revision 157050)
+++ gcc/testsuite/g++.dg/abi/mangle11.C	(working copy)
@@ -1,10 +1,10 @@
 // { dg-options "-Wabi -fabi-version=1" }
 
 template <typename Q>
-void f (typename Q::X) {}
+void f (typename Q::X) {} // { dg-warning "mangle" }
 
 struct S {
   typedef int X;
 };
 
-template void f<S> (int); // { dg-warning "mangle" }
+template void f<S> (int); // { dg-message "instantiated" }
Index: gcc/testsuite/g++.dg/template/cond2.C
===================================================================
--- gcc/testsuite/g++.dg/template/cond2.C	(revision 157050)
+++ gcc/testsuite/g++.dg/template/cond2.C	(working copy)
@@ -3,8 +3,8 @@
 
 template<int X> class c;
 
-template<int X, int Y> int test(c<X ? : Y>&);
+template<int X, int Y> int test(c<X ? : Y>&); // { dg-error "omitted" }
 
 void test(c<2>*c2) {
-	test<0, 2>(*c2); // { dg-error "omitted" }
+	test<0, 2>(*c2); // { dg-message "instantiated" }	
 }
Index: gcc/testsuite/g++.dg/template/pr35240.C
===================================================================
--- gcc/testsuite/g++.dg/template/pr35240.C	(revision 157050)
+++ gcc/testsuite/g++.dg/template/pr35240.C	(working copy)
@@ -4,9 +4,9 @@
 
 template<int> struct A {};
 
-template<int N> A<sizeof(new int[N][N])> foo();
+template<int N> A<sizeof(new int[N][N])> foo(); // { dg-message "unimplemented" }
 
 void bar()
 {
-  foo<1>(); // { dg-message "unimplemented" }
+  foo<1>(); // { dg-message "instantiated" }
 }



More information about the Gcc-patches mailing list