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]

PATCH: PR target/37843:[4.4 Regression] unaligned stack in main due to tail call optimization


Hi,

Where there is a tail call in a leaf function, we fail to align the stack
since we check max_used_stack_slot_alignment for stack requirement. For
tail call, we should check stack_alignment_needed. This patch is tested
on Linux/ia32.  OK for trunk?

Thanks.


H.J.
----
gcc/

2008-10-15  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/37843
	* config/i386/i386.c (ix86_finalize_stack_realign_flags): Don't
	check max_used_stack_slot_alignment for tail call.

gcc/testsuite/

2008-10-15  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/37843
	* gcc.target/i386/align-main-3.c: New.

--- gcc/config/i386/i386.c.sib	2008-10-08 03:39:56.000000000 -0700
+++ gcc/config/i386/i386.c	2008-10-15 17:42:06.000000000 -0700
@@ -7835,7 +7835,8 @@ ix86_finalize_stack_realign_flags (void)
     = (crtl->parm_stack_boundary > ix86_incoming_stack_boundary
        ? crtl->parm_stack_boundary : ix86_incoming_stack_boundary);
   unsigned int stack_realign = (incoming_stack_boundary
-				< (current_function_is_leaf
+				< ((current_function_is_leaf
+				    && !crtl->tail_call_emit)
 				   ? crtl->max_used_stack_slot_alignment
 				   : crtl->stack_alignment_needed));
 
--- gcc/testsuite/gcc.target/i386/align-main-3.c.sib	2008-10-15 17:37:36.000000000 -0700
+++ gcc/testsuite/gcc.target/i386/align-main-3.c	2008-10-15 17:52:56.000000000 -0700
@@ -0,0 +1,12 @@
+/* Test for stack alignment with sibcall optimization.  */
+/* { dg-do compile { target { { i?86-*-linux* x86_64-*-linux* } && ilp32 } } } */
+/* { dg-options "-O2 -mpreferred-stack-boundary=4 -mincoming-stack-boundary=2" } */
+/* { dg-final { scan-assembler "andl\[\\t \]*\\$-16,\[\\t \]*%\[re\]?sp" } } */
+
+extern int foo (void);
+
+int
+main ()
+{
+  return foo ();
+}


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