re PR target/85593 (GCC on ARM allocates R3 for local variable when calling naked...
authorJakub Jelinek <jakub@redhat.com>
Thu, 6 Dec 2018 23:41:04 +0000 (00:41 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 6 Dec 2018 23:41:04 +0000 (00:41 +0100)
PR target/85593
* final.c (rest_of_handle_final): Don't call collect_fn_hard_reg_usage
for functions with naked attribute.

* gcc.target/i386/pr85593.c: New test.

From-SVN: r266881

gcc/ChangeLog
gcc/final.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/i386/pr85593.c [new file with mode: 0644]

index f2512ba68cb573fd14c681f9b173bbae79b84e25..e75e78563589764ee2513c97bd1103a49b54dad1 100644 (file)
@@ -1,5 +1,9 @@
 2018-12-07  Jakub Jelinek  <jakub@redhat.com>
 
+       PR target/85593
+       * final.c (rest_of_handle_final): Don't call collect_fn_hard_reg_usage
+       for functions with naked attribute.
+
        PR c/88367
        * tree-vrp.c (extract_range_from_binary_expr): For POINTER_PLUS_EXPR
        with -fno-delete-null-pointer-checks, set_nonnull only if the pointer
index f707d2fc0bcd934d0c7871db6e70ca0924bbcd05..423318129dd41cca8425ddc8e406e5d495baa84f 100644 (file)
@@ -4659,7 +4659,11 @@ rest_of_handle_final (void)
   final_start_function_1 (&first, asm_out_file, &seen, optimize);
   final_1 (first, asm_out_file, seen, optimize);
   if (flag_ipa_ra
-      && !lookup_attribute ("noipa", DECL_ATTRIBUTES (current_function_decl)))
+      && !lookup_attribute ("noipa", DECL_ATTRIBUTES (current_function_decl))
+      /* Functions with naked attributes are supported only with basic asm
+        statements in the body, thus for supported use cases the information
+        on clobbered registers is not available.  */
+      && !lookup_attribute ("naked", DECL_ATTRIBUTES (current_function_decl)))
     collect_fn_hard_reg_usage ();
   final_end_function ();
 
index a317d8798eb7d7f827fa6aacaae197f9922b8d96..03f405101df13b1ca91126f870e61a41f80a252e 100644 (file)
@@ -1,5 +1,8 @@
 2018-12-07  Jakub Jelinek  <jakub@redhat.com>
 
+       PR target/85593
+       * gcc.target/i386/pr85593.c: New test.
+
        PR rtl-optimization/85770
        * gcc.target/i386/pr85770.c: Require int128 effective target.
 
diff --git a/gcc/testsuite/gcc.target/i386/pr85593.c b/gcc/testsuite/gcc.target/i386/pr85593.c
new file mode 100644 (file)
index 0000000..092f9cb
--- /dev/null
@@ -0,0 +1,30 @@
+/* PR target/85593 */
+/* { dg-do run { target { { i?86-*-linux* x86_64-*-linux* } && lp64 } } } */
+/* { dg-options "-O2" } */
+
+__attribute__((naked)) void
+bar (void)
+{
+  asm ("xorl %eax, %eax\n\t"
+       "xorl %edx, %edx\n\t"
+       "xorl %ecx, %ecx\n\t"
+       "xorl %esi, %esi\n\t"
+       "xorl %edi, %edi\n\t"
+       "xorl %r8d, %r8d\n\t"
+       "xorl %r9d, %r9d\n\t"
+       "xorl %r10d, %r10d\n\t"
+       "xorl %r11d, %r11d\n\t"
+       "ret");
+}
+
+int
+main ()
+{
+  int a = 42;
+  asm ("" : "+r" (a));
+  bar ();
+  asm ("" : "+r" (a));
+  if (a != 42)
+    __builtin_abort ();
+  return 0;
+}