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]

[LTO merge] Source location context for mangling errors


This is related to the free-lang-data patches I posted earlier
(http://gcc.gnu.org/ml/gcc-patches/2009-09/msg00125.html).

When the mangler encounters an error it uses input_location to
provide line number information for the diagnostic message.
Since we are now mangling in an IPA pass, input_location is
essentially random (typically pointing to the end of the file).

This is causing us to give bad line number information for a
couple of C++ testcases.

I'm not quite sure how to handle this case.  One way would be to
look for a statement that uses the DECL being mangled and set
input_location to that statement.  However, it's not clear to me
what statement would be a good one to choose.  The first one?
Does it matter?

Another option is to choose the locus for the symbol declaration.
Since mangling is done on the symbol regardless of where it's
used, this seemed the more natural way for me (notice where the
error messages got relocated in the two testcases).

However, I don't know if this makes sense.  In these two test
cases, emitting the message where the symbol is declared seems
clearer to me than what we previously did, but I may just be
rationalizing this approach because it was easy to implement.

It would not be impossible to do a search for the best location
where a symbol should be mangled, but I need to know what
criteria to use.

Otherwise, is this acceptable?  Testing is ongoing.


Thanks.  Diego.


	* tree.c (free_lang_data_in_cgraph): Set input_location to
	the location of the symbol getting a new assembler name.

testsuite/ChangeLog

	* g++.dg/template/cond2.C: Adjust expected line location for the
	error.
	* g++.dg/template/pr35240.C: Likewise.

diff --git a/testsuite/g++.dg/template/cond2.C b/testsuite/g++.dg/template/cond2.C
index abb6ebb..e6bd19d 100644
--- a/testsuite/g++.dg/template/cond2.C
+++ b/testsuite/g++.dg/template/cond2.C
@@ -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);
 }
diff --git a/testsuite/g++.dg/template/pr35240.C b/testsuite/g++.dg/template/pr35240.C
index de82897..1972cf7 100644
--- a/testsuite/g++.dg/template/pr35240.C
+++ b/testsuite/g++.dg/template/pr35240.C
@@ -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>();
 }
diff --git a/tree.c b/tree.c
index 1e90c1b..185cd54 100644
--- a/tree.c
+++ b/tree.c
@@ -4817,7 +4808,25 @@ free_lang_data_in_cgraph (void)
      for mangling.  This breaks mangling on interdependent decls.  */
   for (i = 0; VEC_iterate (tree, fld.decls, i, t); i++)
     if (need_assembler_name_p (t))
-      lang_hooks.set_decl_assembler_name (t);
+      {
+	/* When setting DECL_ASSEMBLER_NAME, the C++ mangler may emit
+	   diagnostics that use input_location to show locus
+	   information.  The problem here is that, at this point,
+	   input_location is generally anchored to the end of the file
+	   (since the parser is long gone), so we don't have a good
+	   position to pin it to.
+
+	   To alleviate this problem, this uses the location of T's
+	   declaration.  Examples of this are
+	   testsuite/g++.dg/template/cond2.C and
+	   testsuite/g++.dg/template/pr35240.C.  */
+	location_t saved_location = input_location;
+	input_location = DECL_SOURCE_LOCATION (t);
+
+	decl_assembler_name (t);
+
+	input_location = saved_location;
+      }
 
   /* Traverse every decl found freeing its language data.  */
   for (i = 0; VEC_iterate (tree, fld.decls, i, t); i++)


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