[PATCH, PR 39259] Set calls_setjmp and calls_alloca if necessary when versioning functions

Martin Jambor mjambor@suse.cz
Wed Feb 25 18:20:00 GMT 2009


On Tue, Feb 24, 2009 at 02:58:02PM +0100, Richard Guenther wrote:
> On Tue, Feb 24, 2009 at 2:43 PM, Martin Jambor <mjambor@suse.cz> wrote:
> > Hi,
> >
> > the following patch removes the assert  that was hit in PR 39259 which
> > was hit when a function calling setjump was being versioned altogether
> > with a  similar one  for functions calling  alloca.  It also  sets the
> > flags  for the  new  version if  it  detects such  calls when  copying
> > function bodies.
> >
> > Honza suggested I do this rather than simply copying the flags because
> > in near  future we are likely to  do copies of only  selected parts of
> > functions.
> >
> > It  does  fix  the  reported  testcase and  I  have  bootstrapped  and
> > regression tested  this patch  (on x86_64-linux-gnu, rev  144403) with
> > extra asserts to  make sure the flags in the old  and new version were
> > the same.  I will redo this  with this exact patch to follow the rules
> > but I do not expect any problems.
> >
> > I do  not really know what a  testcase for a removed  assert like this
> > should look like.
> >
> > Is this ok for trunk if it rebootstraps fine?
> 
> Ok if you add the testcase from the PR to g++.dg/torture/
> 
> Thanks,
> Richard.

OK, this is what I committed as revision 144428.

Thanks,

Martin


2009-02-25  Martin Jambor  <mjambor@suse.cz>

	* tree-inline.c (initialize_cfun): Remove asserts for calls_setjmp and
	alls_alloca function flags.
	(copy_bb): Set calls_setjmp and alls_alloca function flags if such
	calls are detected.

Index: gcc/testsuite/g++.dg/torture/pr39259.C
===================================================================
--- gcc/testsuite/g++.dg/torture/pr39259.C	(revision 0)
+++ gcc/testsuite/g++.dg/torture/pr39259.C	(revision 0)
@@ -0,0 +1,40 @@
+// PR tree-optimization/39259
+// { dg-do compile }
+// { dg-options "-O2" }
+
+
+extern "C" int __mysetjmp () __attribute__ ((__returns_twice__));
+
+class TContStatus {};
+
+class TContEvent
+{
+public:
+  inline void Execute () throw();
+};
+
+class TCont
+{
+public:
+  TContStatus ReadD (void* buf, int deadline)
+  {
+    TContEvent event;
+    event.Execute ();
+    return TContStatus();
+  }
+  TContStatus ReadI (void *buf)
+  {
+    return ReadD (buf, 1);
+  }
+};
+
+void TContEvent::Execute () throw ()
+{
+  __mysetjmp();
+}
+
+void Broken (TCont *mCont)
+{
+  mCont->ReadI(0);
+  mCont->ReadI(0);
+}
Index: gcc/tree-inline.c
===================================================================
--- gcc/tree-inline.c	(revision 144406)
+++ gcc/tree-inline.c	(working copy)
@@ -1398,6 +1398,7 @@
 	    {
 	      struct cgraph_node *node;
 	      struct cgraph_edge *edge;
+	      int flags;
 
 	      switch (id->transform_call_graph_edges)
 		{
@@ -1429,6 +1430,13 @@
 	      default:
 		gcc_unreachable ();
 		}
+
+	      flags = gimple_call_flags (stmt);
+
+	      if (flags & ECF_MAY_BE_ALLOCA)
+		cfun->calls_alloca = true;
+	      if (flags & ECF_RETURNS_TWICE)
+		cfun->calls_setjmp = true;
 	    }
 
 	  /* If you think we can abort here, you are wrong.
@@ -1745,10 +1753,6 @@
   gcc_assert (cfun->cfg == NULL);
   gcc_assert (cfun->decl == new_fndecl);
 
-  /* No need to copy; this is initialized later in compilation.  */
-  gcc_assert (!src_cfun->calls_setjmp);
-  gcc_assert (!src_cfun->calls_alloca);
-
   /* Copy items we preserve during clonning.  */
   cfun->static_chain_decl = src_cfun->static_chain_decl;
   cfun->nonlocal_goto_save_area = src_cfun->nonlocal_goto_save_area;



More information about the Gcc-patches mailing list