Commit d35a1ef1 by H.J. Lu Committed by H.J. Lu

re PR middle-end/37843 (unaligned stack in main due to tail call optimization)

gcc/

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

	PR middle-end/37843
	* config/i386/i386.c (ix86_function_ok_for_sibcall): Return
	false if we need to align the outgoing stack.
	(ix86_update_stack_boundary): Check parm_stack_boundary.

gcc/testsuite/

2008-11-25  H.J. Lu  <hongjiu.lu@intel.com>

	PR middle-end/37843
	* gcc.target/i386/align-main-3.c: New.
	* gcc.target/i386/pr37843-1.c: Likewise.
	* gcc.target/i386/pr37843-2.c: Likewise.
	* gcc.target/i386/pr37843-3.c: Likewise.

Co-Authored-By: Joey Ye <joey.ye@intel.com>

From-SVN: r142193
parent 5308fd74
2008-11-25 H.J. Lu <hongjiu.lu@intel.com>
Joey Ye <joey.ye@intel.com>
PR middle-end/37843
* config/i386/i386.c (ix86_function_ok_for_sibcall): Return
false if we need to align the outgoing stack.
(ix86_update_stack_boundary): Check parm_stack_boundary.
2008-11-25 Richard Guenther <rguenther@suse.de>
PR middle-end/38151
......@@ -4112,6 +4112,11 @@ ix86_function_ok_for_sibcall (tree decl, tree exp)
&& ix86_function_regparm (TREE_TYPE (decl), NULL) >= 3)
return false;
/* If we need to align the outgoing stack, then sibcalling would
unalign the stack, which may break the called function. */
if (ix86_incoming_stack_boundary < PREFERRED_STACK_BOUNDARY)
return false;
/* Otherwise okay. That also includes certain types of indirect calls. */
return true;
}
......@@ -7770,6 +7775,11 @@ ix86_update_stack_boundary (void)
TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl))))
ix86_incoming_stack_boundary = MIN_STACK_BOUNDARY;
/* The incoming stack frame has to be aligned at least at
parm_stack_boundary. */
if (ix86_incoming_stack_boundary < crtl->parm_stack_boundary)
ix86_incoming_stack_boundary = crtl->parm_stack_boundary;
/* Stack at entrance of main is aligned by runtime. We use the
smallest incoming stack boundary. */
if (ix86_incoming_stack_boundary > MAIN_STACK_BOUNDARY
......
2008-11-25 H.J. Lu <hongjiu.lu@intel.com>
PR middle-end/37843
* gcc.target/i386/align-main-3.c: New.
* gcc.target/i386/pr37843-1.c: Likewise.
* gcc.target/i386/pr37843-2.c: Likewise.
* gcc.target/i386/pr37843-3.c: Likewise.
2008-11-25 Mikael Morin <mikael.morin@tele2.fr>
PR fortran/36463
......
/* Test for stack alignment with sibcall optimization. */
/* { dg-do compile { target { *-*-linux* && ilp32 } } } */
/* { dg-options "-O2 -mpreferred-stack-boundary=4 -mincoming-stack-boundary=2" } */
/* { dg-final { scan-assembler "andl\[\\t \]*\\$-16,\[\\t \]*%\[re\]?sp" } } */
/* { dg-final { scan-assembler "call\[\\t \]*foo" } } */
/* { dg-final { scan-assembler-not "jmp\[\\t \]*foo" } } */
extern int foo (void);
int
main ()
{
return foo ();
}
/* Test for stack alignment with sibcall optimization. */
/* { dg-options "-O2 -mpreferred-stack-boundary=6 -mincoming-stack-boundary=5" } */
/* { dg-final { scan-assembler "and\[lq\]?\[\\t \]*\\$-64,\[\\t \]*%\[re\]?sp" } } */
/* { dg-final { scan-assembler "call\[\\t \]*foo" } } */
/* { dg-final { scan-assembler-not "jmp\[\\t \]*foo" } } */
extern int foo (void);
int bar (void)
{
return foo();
}
/* Test for stack alignment with sibcall optimization. */
/* { dg-options "-O2 -mpreferred-stack-boundary=6 -mincoming-stack-boundary=6" } */
/* { dg-final { scan-assembler-not "and\[lq\]?\[\\t \]*\\$-64,\[\\t \]*%\[re\]?sp" } } */
/* { dg-final { scan-assembler-not "call\[\\t \]*foo" } } */
/* { dg-final { scan-assembler "jmp\[\\t \]*foo" } } */
extern int foo (void);
int bar (void)
{
return foo();
}
/* Test for stack alignment with sibcall optimization. */
/* { dg-do compile { target { *-*-linux* && ilp32 } } } */
/* { dg-options "-O2 -std=gnu99 -mpreferred-stack-boundary=4 -mincoming-stack-boundary=2" } */
/* { dg-final { scan-assembler-not "andl\[\\t \]*\\$-16,\[\\t \]*%\[re\]?sp" } } */
/* { dg-final { scan-assembler-not "call\[\\t \]*foo" } } */
/* { dg-final { scan-assembler "jmp\[\\t \]*foo" } } */
extern int foo (_Decimal128);
int bar (_Decimal128 x)
{
return foo(x);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment