[backport proposed but not yet approved or applied patch to fix
 PR libffi/56033 on trunk and 4.8 <mikpe@it.uu.se>]

List-Archive: <http://gcc.gnu.org/ml/gcc-patches/>
From: Rainer Orth <ro at CeBiTec dot Uni-Bielefeld dot DE>
Subject: [libffi] Fix several libffi testsuite failures on 64-bit SPARC and PowerPC (PR libffi/56033)
Date: Wed, 15 May 2013 16:19:44 +0200

As reported in the PR, the recent libffi import into the gcc tree caused
a couple of testsuite failures on 64-bit big-endian targets (like SPARC
or PowerPC).

The following patch (mostly by Dominique) fixes them and finally gets us
clean libffi testsuite results.

Tested on sparc-sun-solaris2.11 on mainline and 4.8 branch and
x86_64-unknown-linux-gnu on mainline by myself and powerpc-apple-darwin9
by Dominique.

Ok for mainline and 4.8 branch where those failures represent
regressions from 4.7?

	Rainer


2013-05-15  Dominique d'Humieres  <dominiq@lps.ens.fr>
	    Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	PR libffi/56033
	* testsuite/libffi.call/cls_struct_va1.c (test_fn): Cast resp to
	ffi_arg *.
	* testsuite/libffi.call/cls_uint_va.c (cls_ret_T_fn): Likewise.
	* testsuite/libffi.call/va_1.c (main): Change res to ffi_arg.
	* testsuite/libffi.call/va_struct1.c (main): Likewise.

--- gcc-4.8.0/libffi/testsuite/libffi.call/cls_struct_va1.c.~1~	2012-12-26 17:28:02.000000000 +0100
+++ gcc-4.8.0/libffi/testsuite/libffi.call/cls_struct_va1.c	2013-05-18 11:34:01.876833012 +0200
@@ -35,7 +35,7 @@ test_fn (ffi_cif* cif __UNUSED__, void*
   printf ("%d %d %d %d %d %d %d %d %d %d\n", n, s1.a, s1.b,
 	  l1.a, l1.b, l1.c, l1.d, l1.e,
 	  s2.a, s2.b);
-  * (int*) resp = 42;
+  * (ffi_arg*) resp = 42;
 }
 
 int
--- gcc-4.8.0/libffi/testsuite/libffi.call/cls_uint_va.c.~1~	2012-12-26 17:28:02.000000000 +0100
+++ gcc-4.8.0/libffi/testsuite/libffi.call/cls_uint_va.c	2013-05-18 11:34:01.876833012 +0200
@@ -13,9 +13,9 @@ typedef unsigned int T;
 static void cls_ret_T_fn(ffi_cif* cif __UNUSED__, void* resp, void** args,
 			 void* userdata __UNUSED__)
  {
-   *(T *)resp = *(T *)args[0];
+   *(ffi_arg *)resp = *(T *)args[0];
 
-   printf("%d: %d %d\n", *(T *)resp, *(T *)args[0], *(T *)args[1]);
+   printf("%d: %d %d\n", (int)*(ffi_arg *)resp, *(T *)args[0], *(T *)args[1]);
  }
 
 typedef T (*cls_ret_T)(T, ...);
--- gcc-4.8.0/libffi/testsuite/libffi.call/va_1.c.~1~	2013-01-17 19:24:08.000000000 +0100
+++ gcc-4.8.0/libffi/testsuite/libffi.call/va_1.c	2013-05-18 11:34:01.876833012 +0200
@@ -94,7 +94,7 @@ main (void)
   struct large_tag l1;
 
   int n;
-  int res;
+  ffi_arg res;
 
   unsigned char uc;
   signed char sc;
--- gcc-4.8.0/libffi/testsuite/libffi.call/va_struct1.c.~1~	2012-12-26 17:28:02.000000000 +0100
+++ gcc-4.8.0/libffi/testsuite/libffi.call/va_struct1.c	2013-05-18 11:34:01.876833012 +0200
@@ -61,7 +61,7 @@ main (void)
   struct large_tag l1;
 
   int n;
-  int res;
+  ffi_arg res;
 
   s_type.size = 0;
   s_type.alignment = 0;
