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

Re: PATCH: PR target/34001: Incorrect x86 fastcall behavior


On Thu, Nov 15, 2007 at 08:51:02PM -0800, H.J. Lu wrote:
> On Fri, Nov 16, 2007 at 12:35:47PM +0800, Ye, Joey wrote:
> > HJ,
> > 
> > You patch has a minor problem that fastcall will pass non-scalar integer parameter in EAX/ECX/EDX, which is still imcompatible to MS fastcall. MSVC pass parameter on stack unless it is scalar integer less equal to 32 bits.
> > 
> > With this patch GCC fastcall passes first parameter in EAX when it is not a scalar integer less equal to 32 bits. Check following example and review the patch fixing it:
> > 
> > Here is a patch to fix it:
> > Index: gcc/config/i386/i386.c
> > ===================================================================
> > --- gcc/config/i386/i386.c      (revision 129880)
> > +++ gcc/config/i386/i386.c      (working copy)
> > @@ -4229,9 +4229,12 @@
> >           int regno = cum->regno;
> > 
> >           /* Fastcall allocates the first two DWORD (SImode) or
> > -            smaller arguments to ECX and EDX.  */
> > +            smaller arguments to ECX and EDX if it isn't an
> > +            aggregate type .  */
> >           if (cum->fastcall)
> >             {
> > +             if (type && AGGREGATE_TYPE_P (type))
> > +               break;
> >               if (mode == BLKmode || mode == DImode)
> >                 break;
> >   
> 
> Yes, this version is correct. Thanks.
> 
> 

Here is an equivalent patch.


H.J.
----
2007-11-15  H.J. Lu  <hongjiu.lu@intel.com>
	    Joey Ye <joey.ye@intel.com>

	PR target/34001
	* config/i386/i386.c (function_arg_32): Don't pass aggregate
	arguments in ECX/EDX for fastcall.

--- gcc/config/i386/i386.c.fastcall	2007-11-16 05:41:46.000000000 -0800
+++ gcc/config/i386/i386.c	2007-11-16 05:46:43.000000000 -0800
@@ -4257,10 +4257,12 @@ function_arg_32 (CUMULATIVE_ARGS *cum, e
 	  int regno = cum->regno;
 
 	  /* Fastcall allocates the first two DWORD (SImode) or
-	     smaller arguments to ECX and EDX.  */
+            smaller arguments to ECX and EDX if it isn't an
+            aggregate type .  */
 	  if (cum->fastcall)
 	    {
-	      if (mode == BLKmode || mode == DImode)
+	      if (mode == BLKmode || mode == DImode
+		  || (type && AGGREGATE_TYPE_P (type)))
 	        break;
 
 	      /* ECX not EAX is the first allocated register.  */


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