The testcase for PR51447, on x86_64, uses rbx as a global register
variable for the global PTR variable.

A runtime system might legitimately hold in rbx a value expected to be
preserved across the call to main, but its use as a global register
variable stops main from preserving it.

We've observed failures of this test on x86_64-wrs-vxworks7r2, because
of this problem, and this patch fixes them.  I've also tested it on
x86_64-linux-gnu, -m64 and -m32.  Ok to install?

Since main is not supposed to be callable, I suppose we might instead
prevent global register variables from affecting the registers saved or
restored by main, but I don't have a patch for that.  I could give it a
shot, if there's consensus that that would be a better fix.


for  gcc/testsuite/ChangeLog

        PR rtl-optimization/51447
        * gcc.c-torture/execute/pr51447.c (main): Preserve call-saved
        register.
---
 gcc/testsuite/gcc.c-torture/execute/pr51447.c |    6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/gcc/testsuite/gcc.c-torture/execute/pr51447.c 
b/gcc/testsuite/gcc.c-torture/execute/pr51447.c
index 887ddb7..1d00953 100644
--- a/gcc/testsuite/gcc.c-torture/execute/pr51447.c
+++ b/gcc/testsuite/gcc.c-torture/execute/pr51447.c
@@ -14,6 +14,9 @@ int
 main (void)
 {
   __label__ nonlocal_lab;
+#ifdef __x86_64__
+  void *save = ptr;
+#endif
   __attribute__((noinline, noclone)) void
     bar (void *func)
       {
@@ -25,5 +28,8 @@ main (void)
 nonlocal_lab:
   if (ptr != &&nonlocal_lab)
     abort ();
+#ifdef __x86_64__
+  ptr = save; /* Restore the call-saved register.  */
+#endif
   return 0;
 }

-- 
Alexandre Oliva, freedom fighter    he/him    https://FSFLA.org/blogs/lxo/
Free Software Evangelist              Stallman was right, but he's left :(
GNU Toolchain Engineer           Live long and free, and prosper ethically

Reply via email to