This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[x86 testsuite] preserve full register across main

This test uses a call-saved register as a global variable.  It
attempts to preserve its value across main, but only the lower int
part is preserved, which is not good enough for x86_64, when the
runtime that calls main() happens to hold something in the chosen
register that is not a zero-extension from the 32-bit value, and
rightfully expects the full register to remain unchanged when main()

Tested on x86_64-linux-gnu, both -m64 and -m32.  Ok to install?

for  gcc/testsuite/ChangeLog

	* Preserve full register across
 gcc/testsuite/ |   14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/gcc/testsuite/ b/gcc/testsuite/
index 5641826b4837..3b8cf8e41783 100644
--- a/gcc/testsuite/
+++ b/gcc/testsuite/
@@ -2,12 +2,16 @@
 /* { dg-do run } */
 /* { dg-options "-O2" } */
+/* We need this type to be as wide as the register chosen below, so
+   that, when we preserve it across main, we preserve all of it.  */
+typedef long reg_type;
 #if !__PIC__
-register int k asm("%ebx");
+register reg_type k asm("%ebx");
 #elif __amd64
-register int k asm("%r12");
+register reg_type k asm("%r12");
-register int k asm("%esi");
+register reg_type k asm("%esi");
 void __attribute__((noinline))
@@ -18,7 +22,7 @@ foo()
 void test()
-  int i;
+  reg_type i;
   for (i = 0; i < 10; i += k)
       k = 0;
@@ -28,7 +32,7 @@ void test()
 int main()
-  int old = k;
+  reg_type old = k;
   k = old;
   return 0;

Alexandre Oliva, freedom fighter  he/him
Be the change, be Free!                 FSF Latin America board member
GNU Toolchain Engineer                        Free Software Evangelist
Hay que enGNUrecerse, pero sin perder la terGNUra jamás - Che GNUevara

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]