[LTO][PATCH] Fix segfault in -fwhopr -O1 compilations that warn

Simon Baldwin simonb@google.com
Wed Jan 7 22:49:00 GMT 2009


This patch (temporarily) fixes a segmentation fault in -fwhopr optimized
compilations that issue warnings.


gcc/cp/ChangeLog.lto
2009-01-07  Simon Baldwin  <simonb@google.com>

	* error.c (dump_typename): Emit placeholder in place of nulled
	TYPE_CONTEXT in diagnostics issued by optimization phases.

gcc/testsuite/ChangeLog.lto
2009-01-07  Simon Baldwin  <simonb@google.com>

	* g++.dg/20090107-1.C: New.


Index: gcc/testsuite/g++.dg/20090107-1.C
===================================================================
--- gcc/testsuite/g++.dg/20090107-1.C	(revision 0)
+++ gcc/testsuite/g++.dg/20090107-1.C	(revision 0)
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-fwhopr -Wuninitialized -O1" }  */
+
+template <typename T> struct Q1 { typedef int x; };
+template <typename T> struct Q2 {
+  typename Q1<T>::x f() {
+    int k;
+    return k; /* { dg-warning "'k' is used uninitialized in this function" }  */
+  }
+};
+int foo() { return Q2<int>().f(); }
Index: gcc/cp/error.c
===================================================================
--- gcc/cp/error.c	(revision 143074)
+++ gcc/cp/error.c	(working copy)
@@ -434,10 +434,23 @@ dump_typename (tree t, int flags)
 {
   tree ctx = TYPE_CONTEXT (t);
 
-  if (TREE_CODE (ctx) == TYPENAME_TYPE)
-    dump_typename (ctx, flags);
+  /* FIXME lto: For warnings from optimization phases (uninitialized variable,
+     for example), reset_type_lang_specific may have cleared TYPE_CONTEXTs in
+     LTO compilations, in which case some of the type detail will be missing
+     for a TYPENAME_TYPE (TYPE_CONTEXT held the actual type).  For now, emit
+     a placeholder if there is no TYPE_CONTEXT.  */
+  if (ctx)
+    {
+      if (TREE_CODE (ctx) == TYPENAME_TYPE)
+	dump_typename (ctx, flags);
+      else
+	dump_type (ctx, flags & ~TFF_CLASS_KEY_OR_ENUM);
+    }
   else
-    dump_type (ctx, flags & ~TFF_CLASS_KEY_OR_ENUM);
+    {
+      pp_maybe_space (cxx_pp);
+      pp_identifier (cxx_pp, "<unknown>");
+    }
   pp_cxx_colon_colon (cxx_pp);
   dump_decl (TYPENAME_TYPE_FULLNAME (t), flags);
 }



More information about the Gcc-patches mailing list