diff mbox

[C++] Destroy/clear local_specializations properly in tsubst_pack_expansion (PR c++/51852)

Message ID 20120127130120.GS18768@tyan-ft48-01.lab.bos.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek Jan. 27, 2012, 1:01 p.m. UTC
Hi!

My understanding is that we want to clear local_specializations even when
saved_local_specializations is NULL, if the current function created
the local_specializations htab (otherwise it isn't local, but global).
The problem with that is that it isn't GTY marked and contains TREE_LIST
nodes not references from elsewhere, so the next time we look at the
hashtable we can ICE if they have been GC collected and reused for something
else.

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

In the PR there is also a patch to switch local_specializations into
a pointer_map, I think that would be more efficient, but probably 4.8
material, right?

2012-01-27  Jakub Jelinek  <jakub@redhat.com>

	PR c++/51852
	* pt.c (tsubst_pack_expansion): Delete and restore
	local_specialization whenever need_local_specialization, not just
	when saved_local_specializations is non-NULL.

	* g++.dg/other/gc5.C: New test.


	Jakub

Comments

Jason Merrill Jan. 27, 2012, 5:49 p.m. UTC | #1
OK.

Jason
Jason Merrill Jan. 27, 2012, 5:55 p.m. UTC | #2
On 01/27/2012 08:01 AM, Jakub Jelinek wrote:
> In the PR there is also a patch to switch local_specializations into
> a pointer_map, I think that would be more efficient, but probably 4.8
> material, right?

Yes, that change is OK for 4.8.

Jason
diff mbox

Patch

--- gcc/cp/pt.c.jj	2012-01-26 09:22:19.000000000 +0100
+++ gcc/cp/pt.c	2012-01-27 10:10:38.566458106 +0100
@@ -9582,7 +9582,7 @@  tsubst_pack_expansion (tree t, tree args
         }
     }
 
-  if (saved_local_specializations)
+  if (need_local_specializations)
     {
       htab_delete (local_specializations);
       local_specializations = saved_local_specializations;
--- gcc/testsuite/g++.dg/other/gc5.C.jj	2012-01-27 11:34:51.722005604 +0100
+++ gcc/testsuite/g++.dg/other/gc5.C	2012-01-27 11:33:24.000000000 +0100
@@ -0,0 +1,27 @@ 
+// PR c++/51852
+// { dg-do compile }
+// { dg-options "-std=gnu++11 --param ggc-min-heapsize=0 --param ggc-min-expand=0" }
+
+template <typename, typename>
+class transformed {};
+
+template <class R, class F>
+transformed<F, R> transform (R r, F f);
+
+template <typename, typename>
+class joined {};
+
+template <typename T, typename U>
+joined<T, U> join (T t, U u);
+
+template <typename T, typename U, typename V, typename... Rest>
+auto join (T t, U u, V v, Rest... rest) -> decltype (join (join (t, u), v, rest...));
+
+template <typename F, typename... Rs>
+auto polymorphic_transform (F f, Rs... rs) -> decltype (join (transform(rs, f)...));
+
+int
+main ()
+{
+  polymorphic_transform (0, 0, 0);
+}