public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH to instantiation of lambda closure
@ 2015-11-12  0:52 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2015-11-12  0:52 UTC (permalink / raw)
  To: gcc-patches List

[-- Attachment #1: Type: text/plain, Size: 397 bytes --]

While looking into something else I noticed a GC problem with lambdas: 
it is possible to collect after instantiating the closure type, which 
implies instantiating the operator(), while we're in the middle of an 
expression, leading to corruption.  We deal with this sort of thing in 
mark_used by preventing collection, so let's do the same here.

Tested x86_64-pc-linux-gnu, applying to trunk.

[-- Attachment #2: lambda-inst.patch --]
[-- Type: text/x-patch, Size: 869 bytes --]

commit a881d7bf5eb64ee5f110ae0ff206805da560f3df
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Nov 11 15:48:01 2015 -0500

    	* pt.c (instantiate_class_template_1): Set function_depth around
    	instantiation of lambda op().

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index bfea8e2..076c1c7 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -10168,7 +10168,12 @@ instantiate_class_template_1 (tree type)
 	{
 	  if (!DECL_TEMPLATE_INFO (decl)
 	      || DECL_TEMPLATE_RESULT (DECL_TI_TEMPLATE (decl)) != decl)
-	    instantiate_decl (decl, false, false);
+	    {
+	      /* Set function_depth to avoid garbage collection.  */
+	      ++function_depth;
+	      instantiate_decl (decl, false, false);
+	      --function_depth;
+	    }
 
 	  /* We need to instantiate the capture list from the template
 	     after we've instantiated the closure members, but before we

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-11-12  0:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-12  0:52 C++ PATCH to instantiation of lambda closure Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).