This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java 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]

[patch] libffi: SH: Fix a latent bug


Hi,

SH's ffi_call could clobber a few extra bytes when the return value
is a small structure.  FRAME_GROWS_DOWNWARD patch

http://gcc.gnu.org/ml/gcc-patches/2005-07/msg00376.html

reveals this latent bug on cls_1_1byte.c test.  The attached patch
is to fix it.  With it and with/without FRAME_GROWS_DOWNWARD patch,
the result of make check on sh4-unknown-linux-gnu is:

                === libffi Summary ===

# of expected passes            219
# of unsupported tests          2

and there is no new failure on libjava.  Ok for mainline?

Regards,
	kaz
--
2005-07-09  Kaz Kojima  <kkojima@gcc.gnu.org>

	* src/sh/ffi.c (ffi_call): Handle small structures correctly.
	Remove empty line.

diff -uprN ORIG/gcc/libffi/src/sh/ffi.c LOCAL/gcc/libffi/src/sh/ffi.c
--- ORIG/gcc/libffi/src/sh/ffi.c	2004-10-25 16:59:30.000000000 +0900
+++ LOCAL/gcc/libffi/src/sh/ffi.c	2005-07-09 15:50:53.000000000 +0900
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------
-   ffi.c - Copyright (c) 2002, 2003, 2004 Kaz Kojima
+   ffi.c - Copyright (c) 2002, 2003, 2004, 2005 Kaz Kojima
    
    SuperH Foreign Function Interface 
 
@@ -427,6 +427,7 @@ void ffi_call(/*@dependent@*/ ffi_cif *c
 	      /*@dependent@*/ void **avalue)
 {
   extended_cif ecif;
+  UINT64 trvalue;
 
   ecif.cif = cif;
   ecif.avalue = avalue;
@@ -434,7 +435,10 @@ void ffi_call(/*@dependent@*/ ffi_cif *c
   /* If the return value is a struct and we don't have a return	*/
   /* value address then we need to make one		        */
 
-  if ((rvalue == NULL) && 
+  if (cif->rtype->type == FFI_TYPE_STRUCT
+      && return_type (cif->rtype) != FFI_TYPE_STRUCT)
+    ecif.rvalue = &trvalue;
+  else if ((rvalue == NULL) && 
       (cif->rtype->type == FFI_TYPE_STRUCT))
     {
       /*@-sysunrecog@*/
@@ -443,7 +447,6 @@ void ffi_call(/*@dependent@*/ ffi_cif *c
     }
   else
     ecif.rvalue = rvalue;
-    
 
   switch (cif->abi) 
     {
@@ -457,6 +460,11 @@ void ffi_call(/*@dependent@*/ ffi_cif *c
       FFI_ASSERT(0);
       break;
     }
+
+  if (rvalue
+      && cif->rtype->type == FFI_TYPE_STRUCT
+      && return_type (cif->rtype) != FFI_TYPE_STRUCT)
+    memcpy (rvalue, &trvalue, cif->rtype->size);
 }
 
 extern void ffi_closure_SYSV (void);


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