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] Disallow cloning of __attribute__((optimize (0))) functions (PR ipa/60026)


Hi!

As discussed in the PR, this patch disallows cloning of
non-optimized functions, which doesn't work properly e.g. because
-O0 functions don't have vdef/vuses, but also doesn't sound like
something people would like to happen if they say particular function
shouldn't be optimized.  If everything is compiled with -O0, we
don't perform the IPA optimizations at all.

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

2014-02-04  Jakub Jelinek  <jakub@redhat.com>

	PR ipa/60026
	* tree-inline.c (copy_forbidden): Fail for
	__attribute__((optimize (0))) functions.

	* c-c++-common/torture/pr60026.c: New test.

--- gcc/tree-inline.c.jj	2014-02-01 09:39:59.000000000 +0100
+++ gcc/tree-inline.c	2014-02-03 19:33:52.146931674 +0100
@@ -3315,6 +3315,18 @@ copy_forbidden (struct function *fun, tr
 	goto fail;
       }
 
+  tree fs_opts;
+  fs_opts = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fun->decl);
+  if (fs_opts)
+    {
+      struct cl_optimization *os = TREE_OPTIMIZATION (fs_opts);
+      if (!os->x_optimize)
+	{
+	  reason = G_("function %q+F compiled without optimizations");
+	  goto fail;
+	}
+    }
+
  fail:
   fun->cannot_be_copied_reason = reason;
   fun->cannot_be_copied_set = true;
--- gcc/testsuite/c-c++-common/torture/pr60026.c.jj	2014-02-03 18:18:37.395092543 +0100
+++ gcc/testsuite/c-c++-common/torture/pr60026.c	2014-02-03 18:18:26.000000000 +0100
@@ -0,0 +1,28 @@
+/* PR ipa/60026 */
+/* { dg-do compile } */
+
+struct S { int f; } a;
+
+__attribute__((optimize (0)))
+struct S foo (int x, struct S y)
+{
+  int b = y.f;
+  return a; 
+}
+
+void
+bar ()
+{
+  while (a.f)
+    {
+      struct S c = {0};
+      foo (0, c);
+    }
+}
+
+int
+main ()
+{
+  bar (); 
+  return 0;
+}

	Jakub


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