Patchwork [C++] Fix PR51262

login
register
mail settings
Submitter Richard Guenther
Date Dec. 9, 2011, 9:16 a.m.
Message ID <alpine.LNX.2.00.1112091014280.4527@zhemvz.fhfr.qr>
Download mbox | patch
Permalink /patch/130324/
State New
Headers show

Comments

Richard Guenther - Dec. 9, 2011, 9:16 a.m.
The following fixes PR51262, the new type alias code does

else if (CLASS_TYPE_P (t) && !TYPE_DECL_ALIAS_P (TYPE_NAME (t)))

which ICEs when t is a type with an anonymous name with -flto
because we clear such TYPE_NAMEs during cp_free_lang_data.
It turns out that doing so is no longer necessary because we
now ignore names when merging canonical types (and thus C and
C++ interoperate just fine).

Bootstrapped and tested on x86_64-unknown-linux-gnu, ok for trunk?

Thanks,
Richard.

2011-12-09  Richard Guenther  <rguenther@suse.de>

	PR lto/51262
	* tree.c (cp_free_lang_data): No longer clear anonymous names.

	* g++.dg/opt/pr51262.C: New testcase.
Jason Merrill - Dec. 9, 2011, 8:14 p.m.
OK.

Jason

Patch

Index: gcc/cp/tree.c
===================================================================
--- gcc/cp/tree.c	(revision 182117)
+++ gcc/cp/tree.c	(working copy)
@@ -3479,17 +3479,6 @@  cp_free_lang_data (tree t)
       DECL_EXTERNAL (t) = 1;
       TREE_STATIC (t) = 0;
     }
-  if (CP_AGGREGATE_TYPE_P (t)
-      && TYPE_NAME (t))
-    {
-      tree name = TYPE_NAME (t);
-      if (TREE_CODE (name) == TYPE_DECL)
-	name = DECL_NAME (name);
-      /* Drop anonymous names.  */
-      if (name != NULL_TREE
-	  && ANON_AGGRNAME_P (name))
-	TYPE_NAME (t) = NULL_TREE;
-    }
   if (TREE_CODE (t) == NAMESPACE_DECL)
     {
       /* The list of users of a namespace isn't useful for the middle-end
Index: gcc/testsuite/g++.dg/opt/pr51262.C
===================================================================
--- gcc/testsuite/g++.dg/opt/pr51262.C	(revision 0)
+++ gcc/testsuite/g++.dg/opt/pr51262.C	(revision 0)
@@ -0,0 +1,21 @@ 
+// { dg-do compile }
+// { dg-require-effective-target lto }
+// { dg-options "-flto -g" }
+
+template < typename > void *
+bar (int *p)
+{
+  union
+    {
+      int *p;
+    }
+  u;
+  u.p = p;
+  return u.p;
+}
+
+void
+foo (int *p)
+{
+  bar < void >(p);
+}