Submitted By:            Kevin Day <kevin AT kevux DOT org>
Date:                    2006-08-07
Initial Package Version: 4.1.1
Upstream Status:         Present upstream and waiting to be applied to 4.2.0
Description:             ffast-math segfaults.  This contains multiple fixes pulled directly from upstream.
for authors & upstream location see:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28621 - Patch by Jan Hubicka   <hubicka AT gcc DOT gnu DOT org>
http://gcc.gnu.org/ml/gcc-patches/2006-03/msg01179.html - Patch by Lu Hongjiu <hongjiu DOT lu AT intel DOT com> 

--- gcc-4.1.1/gcc/config/i386/crtfastmath.c.orig	2006-08-07 22:41:36.000000000 -0500
+++ gcc-4.1.1/gcc/config/i386/crtfastmath.c	2006-08-07 23:06:49.000000000 -0500
@@ -38,6 +38,9 @@
 #define SSE	(1 << 25)
 
 static void __attribute__((constructor))
+#ifndef __x86_64__
+__attribute__ ((force_align_arg_pointer))
+#endif
 set_fast_math (void)
 {
 #ifndef __x86_64__
@@ -75,7 +78,7 @@
       if (edx & FXSAVE)
 	{
 	  /* Check if DAZ is available.  */
-	  struct
+	  struct fxsave
 	    {
 	      unsigned short int cwd;
 	      unsigned short int swd;
@@ -90,13 +93,17 @@
 	      long int st_space[32];
 	      long int xmm_space[32];
 	      long int padding[56];
-	    } __attribute__ ((aligned (16))) fxsave;
+	    } *fxsave;
+
+	  fxsave = (struct fxsave *)
+	    (((unsigned long) __builtin_alloca (sizeof (*fxsave) + 15))
+	     & ~15L);
 
-	  __builtin_memset (&fxsave, 0, sizeof (fxsave));
+	  __builtin_memset (fxsave, 0, sizeof (*fxsave));
 
-	  asm volatile ("fxsave %0" : "=m" (fxsave) : "m" (fxsave));
+	  asm volatile ("fxsave %0" : "=m" (*fxsave) : "m" (*fxsave));
 
-	  if (fxsave.mxcsr_mask & MXCSR_DAZ)
+	  if (fxsave->mxcsr_mask & MXCSR_DAZ)
 	    mxcsr |= MXCSR_DAZ;
 	}
 
