[PATCH] Fix C++ thunk aliases (PR tree-optimization/37095)

Jakub Jelinek jakub@redhat.com
Tue Sep 2 09:13:00 GMT 2008


Hi!

thunks are created only after cgraph_global_info_ready = 1, but the newly
added assembler_name_hash hashtable assumes that no new nodes are created
after cgraph_node_for_asm is called for the first time.
The following patch fixes it by maintaining the hash table in cgraph_node
once it has been created.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2008-09-02  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/37095
	* cgraph.c (cgraph_node): When creating new cgraph node after
	assembler_name_hash has been populated, record it in the hash
	table.

	* g++.dg/inherit/thunk9.C: New test.

--- gcc/cgraph.c.jj	2008-08-29 20:31:50.000000000 +0200
+++ gcc/cgraph.c	2008-09-01 20:57:26.000000000 +0200
@@ -453,7 +453,21 @@ cgraph_node (tree decl)
       node->origin->nested = node;
       node->master_clone = node;
     }
+  if (assembler_name_hash)
+    {
+      void **aslot;
+      tree name = DECL_ASSEMBLER_NAME (decl);
 
+      aslot = htab_find_slot_with_hash (assembler_name_hash, name,
+					decl_assembler_name_hash (name),
+					INSERT);
+      /* We can have multiple declarations with same assembler name. For C++
+	 it is __builtin_strlen and strlen, for instance.  Do we need to
+	 record them all?  Original implementation marked just first one
+	 so lets hope for the best.  */
+      if (*aslot == NULL)
+	*aslot = node;
+    }
   return node;
 }
 
--- gcc/testsuite/g++.dg/inherit/thunk9.C.jj	2008-09-01 21:00:21.000000000 +0200
+++ gcc/testsuite/g++.dg/inherit/thunk9.C	2008-09-01 20:59:30.000000000 +0200
@@ -0,0 +1,14 @@
+// PR tree-optimization/37095
+// { dg-options "-O" }
+
+struct A
+{
+  virtual A *foo ();
+};
+
+struct B : virtual A
+{
+  virtual B *foo () { return 0; }
+};
+
+B b;

	Jakub



More information about the Gcc-patches mailing list