This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix PR tree-optimization/20076


Hi!

If __builtin_apply_args or __builtin_return are called from an inlined
function, they save arguments resp. return from the function it has been
inlined into.
Given that these builtins are very rare and handling these builtins
for the tree level inlined functions would be non-trivial, I'm proposing
just not to inline those functions.
Ok to commit if bootstrap/regtesting succeeds?

2005-04-05  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/20076
	* tree-inline.c (inline_forbidden_p_1): Prevent inlining functions
	that call __builtin_return or __builtin_apply_args.

	* gcc.dg/builtin-apply4.c: New test.

--- gcc/tree-inline.c.jj	2005-04-04 13:06:29.000000000 +0200
+++ gcc/tree-inline.c	2005-04-05 13:09:02.000000000 +0200
@@ -1017,6 +1017,17 @@ inline_forbidden_p_1 (tree *nodep, int *
 		   "it uses non-local goto");
 	    return node;
 
+	  case BUILT_IN_RETURN:
+	  case BUILT_IN_APPLY_ARGS:
+	    /* If a __builtin_apply_args caller would be inlined,
+	       it would be saving arguments of the function it has
+	       been inlined into.  Similarly __builtin_return would
+	       return from the function the inline has been inlined into.  */
+	    inline_forbidden_reason
+	      = N_("%Jfunction %qF can never be inlined because "
+		   "it uses __builtin_return or __builtin_apply_args");
+	    return node;
+
 	  default:
 	    break;
 	  }
--- gcc/testsuite/gcc.dg/builtin-apply4.c.jj	2005-04-05 12:59:51.000000000 +0200
+++ gcc/testsuite/gcc.dg/builtin-apply4.c	2005-04-05 13:04:25.000000000 +0200
@@ -0,0 +1,30 @@
+/* PR tree-optimization/20076 */
+/* { dg-options "-O2" } */
+/* { dg-do run } */
+
+extern void abort (void);
+
+double
+foo (int arg)
+{
+  if (arg != 116)
+    abort();
+  return arg + 1;
+}
+
+inline double
+bar (int arg)
+{
+  foo (arg);
+  __builtin_return (__builtin_apply ((void (*) ()) foo,
+				     __builtin_apply_args (), 16));
+}
+
+int
+main (int argc, char **argv)
+{
+  if (bar (116) != 117.0)
+    abort ();
+
+  return 0;
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]