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]

-mpreferred-stack-boundary may overflow


One of our customers noticed that the upper limit of
-mpreferred-stack-boundary is not low enough to prevent overflows in
the computed stack boundary, because the result of the shift is
multiplied by BITS_PER_UNIT.  Besides, it assumes `int' (the type used
to hold the computed alignment) is 32-bits wide, but int is not
guaranteed to be wider than 16 bits.  I don't see much point in
requiring alignments beyond page boundaries, and this upper limit has
the nice property that, when multiplied by BITS_PER_UNIT, it results
in the maximum positive power of two that fits in a 16-bit int.  

This patch fixes this problem, with the nice additional benefit of
catching what I suppose to be the common mistake of using
-mpreferred-stack-boundary=16 when what was intended was
-mpreferred-stack-boundary=4 (1<<4 == 16).

The alternative to preserve the current boundary is to use a
HOST_WIDE_INT (perhaps unsigned?) to hold the computed alignment, but
even then, we might overflow in case HOST_WIDE_INT is no wider than 32
bits.

This was *not* bootstrapped on athlon-pc-linux-gnu; I've just checked
that it compiles.  Ok to install?

Index: gcc/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* config/i386/i386.c (override_options): Set upper limit of
	-mpreferred-stack-boundary to 12.

Index: gcc/config/i386/i386.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/i386/i386.c,v
retrieving revision 1.323
diff -u -p -r1.323 i386.c
--- gcc/config/i386/i386.c 2001/10/22 07:19:01 1.323
+++ gcc/config/i386/i386.c 2001/10/23 09:17:43
@@ -978,8 +978,8 @@ override_options ()
   if (ix86_preferred_stack_boundary_string)
     {
       i = atoi (ix86_preferred_stack_boundary_string);
-      if (i < (TARGET_64BIT ? 3 : 2) || i > 31)
-	error ("-mpreferred-stack-boundary=%d is not between %d and 31", i,
+      if (i < (TARGET_64BIT ? 3 : 2) || i > 12)
+	error ("-mpreferred-stack-boundary=%d is not between %d and 12", i,
 	       TARGET_64BIT ? 3 : 2);
       else
 	ix86_preferred_stack_boundary = (1 << i) * BITS_PER_UNIT;

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me

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