2010-07-24 Jie Zhang Issue #9079 Backport from mainline: gcc/ 2010-07-23 Jie Zhang PR target/44290 * attribs.c (decl_attributes): Insert "noinline" and "noclone" if "naked". * tree-sra.c (ipa_sra_preliminary_function_checks): Return false if ! tree_versionable_function_p. gcc/testsuite/ 2010-07-23 Jie Zhang PR target/44290 * gcc.dg/pr44290-1.c: New test. * gcc.dg/pr44290-2.c: New test. 2010-07-22 Maxim Kuvyrkov Backport from FSF GCC 4.5 branch to fix PR45015: === modified file 'gcc/attribs.c' --- old/gcc/attribs.c 2010-04-02 18:54:46 +0000 +++ new/gcc/attribs.c 2010-08-05 11:39:36 +0000 @@ -278,6 +278,19 @@ 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)) === added file 'gcc/testsuite/gcc.dg/pr44290-1.c' --- old/gcc/testsuite/gcc.dg/pr44290-1.c 1970-01-01 00:00:00 +0000 +++ new/gcc/testsuite/gcc.dg/pr44290-1.c 2010-08-05 11:39:36 +0000 @@ -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" } } */ === added file 'gcc/testsuite/gcc.dg/pr44290-2.c' --- old/gcc/testsuite/gcc.dg/pr44290-2.c 1970-01-01 00:00:00 +0000 +++ new/gcc/testsuite/gcc.dg/pr44290-2.c 2010-08-05 11:39:36 +0000 @@ -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" } } */ === modified file 'gcc/tree-sra.c' --- old/gcc/tree-sra.c 2010-03-17 12:02:35 +0000 +++ new/gcc/tree-sra.c 2010-08-05 11:39:36 +0000 @@ -4096,6 +4096,13 @@ static bool ipa_sra_preliminary_function_checks (struct cgraph_node *node) { + if (!tree_versionable_function_p (current_function_decl)) + { + if (dump_file) + fprintf (dump_file, "Function isn't allowed to be versioned.\n"); + return false; + } + if (!cgraph_node_can_be_local_p (node)) { if (dump_file)