x86 stack frame padding

Richard Henderson rth@redhat.com
Wed May 29 14:02:00 GMT 2002


On Wed, May 29, 2002 at 12:54:41PM +0200, Jan Hubicka wrote:
> Will this work for alloca blocks?

No.  Fixed as follows.

> I think preferred_stack_boundary should not be set to 16 unless there
> is call or alloca, at least it is supposed to work that way.

The issue is that there _was_ a call, but the block it was in
was removed as dead code.

Applied mainline and branch, since this is a regression from 3.1.0.


r~


        * config/i386/i386.c (ix86_compute_frame_layout): Do add bottom
        alignment for alloca.

        * gcc.c-torture/execute/alloca-1.c: New.

Index: config/i386/i386.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/i386.c,v
retrieving revision 1.412
diff -c -p -d -u -r1.412 i386.c
--- config/i386/i386.c	29 May 2002 20:16:50 -0000	1.412
+++ config/i386/i386.c	29 May 2002 20:26:34 -0000
@@ -4148,8 +4148,9 @@ ix86_compute_frame_layout (frame)
   else
     frame->outgoing_arguments_size = 0;
 
-  /* Align stack boundary.  Only needed if we're calling another function.  */
-  if (!current_function_is_leaf)
+  /* Align stack boundary.  Only needed if we're calling another function
+     or using alloca.  */
+  if (!current_function_is_leaf || current_function_calls_alloca)
     frame->padding2 = ((offset + preferred_alignment - 1)
 		       & -preferred_alignment) - offset;
   else
Index: testsuite/gcc.c-torture/execute/alloca-1.c
===================================================================
RCS file: testsuite/gcc.c-torture/execute/alloca-1.c
diff -N testsuite/gcc.c-torture/execute/alloca-1.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gcc.c-torture/execute/alloca-1.c	29 May 2002 20:26:34 -0000
@@ -0,0 +1,21 @@
+/* Verify that alloca storage is sufficiently aligned.  */
+/* ??? May fail if BIGGEST_ALIGNMENT > STACK_BOUNDARY.  Which, I guess
+   can only happen on !STRICT_ALIGNMENT targets.  */
+
+typedef __SIZE_TYPE__ size_t;
+
+struct dummy { int x __attribute__((aligned)); };
+#define BIGGEST_ALIGNMENT __alignof__(struct dummy)
+
+_Bool foo(void)
+{
+  char *p = __builtin_alloca(32);
+  return ((size_t)p & (BIGGEST_ALIGNMENT - 1)) == 0;
+}
+
+int main()
+{
+  if (!foo())
+    abort ();
+  return 0;
+}



More information about the Gcc-patches mailing list