Patchwork Fix PR target/44290 on 4.5 branch

login
register
mail settings
Submitter Jie Zhang
Date Dec. 17, 2010, 5:40 a.m.
Message ID <4D0AF7EB.8040001@codesourcery.com>
Download mbox | patch
Permalink /patch/75836/
State New
Headers show

Comments

Jie Zhang - Dec. 17, 2010, 5:40 a.m.
This patch backports

http://gcc.gnu.org/ml/gcc-patches/2010-07/msg01827.html  (r162466)

and

http://gcc.gnu.org/ml/gcc-patches/2010-07/msg02105.html  (r162579)

to 4.5 branch as requested in

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44290

I'm now testing it. Is it OK for 4.5 if the testing is good.


Regards,

Patch


	Backport from mainline
	2010-07-23  Jie Zhang  <jie@codesourcery.com>

	PR target/44290
	* attribs.c (decl_attributes): Insert "noinline" and "noclone"
	if "naked".

	testsuite/
	Backport from mainline
	2010-07-23  Jie Zhang  <jie@codesourcery.com>
	PR target/44290
	* gcc.dg/pr44290-1.c: New test.
	* gcc.dg/pr44290-2.c: New test.

Index: attribs.c
===================================================================
--- attribs.c	(revision 167969)
+++ attribs.c	(working copy)
@@ -278,6 +278,19 @@  decl_attributes (tree *node, tree attrib
 	TREE_VALUE (cur_attr) = chainon (opts, TREE_VALUE (cur_attr));
     }
 
+  /* A "naked" function attribute implies "noinline" and "noclone" for
+     those targets that support it.  */
+  if (TREE_CODE (*node) == FUNCTION_DECL
+      && lookup_attribute_spec (get_identifier ("naked"))
+      && lookup_attribute ("naked", attributes) != NULL)
+    {
+      if (lookup_attribute ("noinline", attributes) == NULL)
+	attributes = tree_cons (get_identifier ("noinline"), NULL, attributes);
+
+      if (lookup_attribute ("noclone", attributes) == NULL)
+	attributes = tree_cons (get_identifier ("noclone"),  NULL, attributes);
+    }
+
   targetm.insert_attributes (*node, &attributes);
 
   for (a = attributes; a; a = TREE_CHAIN (a))
Index: testsuite/gcc.dg/pr44290-1.c
===================================================================
--- testsuite/gcc.dg/pr44290-1.c	(revision 0)
+++ testsuite/gcc.dg/pr44290-1.c	(revision 0)
@@ -0,0 +1,18 @@ 
+/* { dg-do compile { target arm*-*-* avr-*-* mcore-*-* rx-*-* spu-*-* } } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+static void __attribute__((naked))
+foo(void *from, void *to)
+{
+  asm volatile("dummy"::"r"(from), "r"(to));
+}
+
+unsigned int fie[2];
+
+void fum(void *to)
+{
+  foo(fie, to);
+}
+
+/* { dg-final { scan-tree-dump "foo \\\(void \\\* from, void \\\* to\\\)" "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */
Index: testsuite/gcc.dg/pr44290-2.c
===================================================================
--- testsuite/gcc.dg/pr44290-2.c	(revision 0)
+++ testsuite/gcc.dg/pr44290-2.c	(revision 0)
@@ -0,0 +1,24 @@ 
+/* { dg-do compile { target arm*-*-* avr-*-* mcore-*-* rx-*-* spu-*-* } } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+static unsigned long __attribute__((naked))
+foo (unsigned long base)
+{
+  asm volatile ("dummy");
+}
+unsigned long
+bar (void)
+{
+  static int start, set;
+
+  if (!set)
+    {
+      set = 1;
+      start = foo (0);
+    }
+
+  return foo (start);
+}
+
+/* { dg-final { scan-tree-dump "foo \\\(long unsigned int base\\\)" "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */