On 14-12-12 04:29 PM, Mike Stump wrote:
On Dec 12, 2014, at 11:38 AM, Ryan Mansfield <rmansfi...@qnx.com> wrote:

Here are a few test tweaks. In 921202-1.c, if STACK_SIZE is used then VLEN will 
blow the stack with 64bit longs. e.g. if STACK_SIZE == 512K then 3 arrays of 
32767 longs means at a minimum 767K of stack will be used at -O0. In pr51447.c, 
the rbx global register is clobbering the rbx of main's caller, which can cause 
test case crashes on return.

2014-12-12  Ryan Mansfield  <rmansfi...@qnx.com>

        * gcc.c-torture/execute/921202-1.c: Adjust VLEN.
        * gcc.c-torture/execute/pr51447.c: Restore rbx for x86-64.
        * gcc.dg/cpp/trad/include.c: Exclude QNX targets.

OK?

Ok for first and third part.  The second one, I would like an rbx/x86_64 person 
to review.

Thanks. rbx is callee saved, and it's being clobbered.

e.g. on Linux x86-64

Breakpoint 1, main ()
at /home/ryan/gnu/gcc/trunk/gcc/testsuite/gcc.c-torture/execute/pr51447.c:13
13      {
1: x/i $pc
=> 0x40054e <main>:    push   %rbp
(gdb) info reg rbx
rbx            0x0      0

(gdb) s
26        return 0;
1: x/i $pc
=> 0x400596 <main+72>: mov    $0x0,%eax
(gdb) info reg rbx
rbx            0x400586 4195718r

The global register var docs say:

"A function that can alter the value of a global register variable cannot safely be called from a function compiled without this variable, because it could clobber the value the caller expects to find there on return. Therefore, the function that is the entry point into the part of the program that uses the global register variable must explicitly save and restore the value that belongs to its caller."

The updated diff switches the test to use inline asm to save/restore rbx instead of the local reg vars, but maybe there's a better way.

Regards,

Ryan Mansfield


Index: gcc/testsuite/gcc.c-torture/execute/921202-1.c
===================================================================
--- gcc/testsuite/gcc.c-torture/execute/921202-1.c	(revision 218685)
+++ gcc/testsuite/gcc.c-torture/execute/921202-1.c	(working copy)
@@ -2,7 +2,7 @@
 #ifndef STACK_SIZE
 #define	VLEN	2055
 #else
-#define VLEN ((STACK_SIZE/16) - 1)
+#define VLEN ((STACK_SIZE/32) - 1)
 #endif
 main ()
 {
Index: gcc/testsuite/gcc.c-torture/execute/pr51447.c
===================================================================
--- gcc/testsuite/gcc.c-torture/execute/pr51447.c	(revision 218685)
+++ gcc/testsuite/gcc.c-torture/execute/pr51447.c	(working copy)
@@ -14,6 +14,10 @@
 main (void)
 {
   __label__ nonlocal_lab;
+#ifdef __x86_64__
+  void *saved_rbx;
+  asm volatile ("movq %%rbx, %0" : "=r" (saved_rbx) : : );
+#endif
   __attribute__((noinline, noclone)) void
     bar (void *func)
       {
@@ -21,9 +25,15 @@
 	goto nonlocal_lab;
       }
   bar (&&nonlocal_lab);
+#ifdef __x86_64__
+  asm volatile ("movq %0, %%rbx" : : "r" (saved_rbx) : "rbx" );
+#endif
   return 1;
 nonlocal_lab:
   if (ptr != &&nonlocal_lab)
     abort ();
+#ifdef __x86_64__
+  asm volatile ("movq %0, %%rbx" : : "r" (saved_rbx) : "rbx" );
+#endif
   return 0;
 }
Index: gcc/testsuite/gcc.dg/cpp/trad/include.c
===================================================================
--- gcc/testsuite/gcc.dg/cpp/trad/include.c	(revision 218685)
+++ gcc/testsuite/gcc.dg/cpp/trad/include.c	(working copy)
@@ -1,11 +1,11 @@
 /* Copyright (c) 2002 Free Software Foundation Inc.  */
 
-/* Test that macros are not expanded in the <> quotes of #inlcude.  */
+/* Test that macros are not expanded in the <> quotes of #include.  */
 
 /* vxWorksCommon.h uses the "#" operator to construct the name of an
    include file, thus making the file incompatible with -traditional-cpp.
    Newlib uses ## when including stdlib.h as of 2007-09-07.  */
-/* { dg-do preprocess { target { { ! vxworks_kernel } && { ! newlib } } } } */
+/* { dg-do preprocess { target { { ! vxworks_kernel } && { ! newlib } && { ! *-*-qnx* } } } } */
 
 #define __STDC__ 1		/* Stop complaints about non-ISO compilers.  */
 #define stdlib 1

Reply via email to