diff options
author | H.J. Lu <hongjiu.lu@intel.com> | 2008-11-25 15:33:27 +0000 |
---|---|---|
committer | H.J. Lu <hjl@gcc.gnu.org> | 2008-11-25 07:33:27 -0800 |
commit | d35a1ef103fd000a52a2d9395be20d53bcadac1e (patch) | |
tree | 943ddede9ec1114f2a6dfe5f3297c697e0afb359 /gcc | |
parent | 5308fd74fdb4e60b11866cadb5fdaa3e42809a1c (diff) | |
download | gcc-d35a1ef103fd000a52a2d9395be20d53bcadac1e.zip gcc-d35a1ef103fd000a52a2d9395be20d53bcadac1e.tar.gz gcc-d35a1ef103fd000a52a2d9395be20d53bcadac1e.tar.bz2 |
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
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/config/i386/i386.c | 10 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/i386/align-main-3.c | 14 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/i386/pr37843-1.c | 12 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/i386/pr37843-2.c | 12 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/i386/pr37843-3.c | 13 |
7 files changed, 77 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 148e7b2..bf00b68 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +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 diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index 8f4680d..1f7d506 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d3c09d1..1548eed 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +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 diff --git a/gcc/testsuite/gcc.target/i386/align-main-3.c b/gcc/testsuite/gcc.target/i386/align-main-3.c new file mode 100644 index 0000000..d2f88d8 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/align-main-3.c @@ -0,0 +1,14 @@ +/* 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 (); +} diff --git a/gcc/testsuite/gcc.target/i386/pr37843-1.c b/gcc/testsuite/gcc.target/i386/pr37843-1.c new file mode 100644 index 0000000..12b70fd --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr37843-1.c @@ -0,0 +1,12 @@ +/* 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(); +} diff --git a/gcc/testsuite/gcc.target/i386/pr37843-2.c b/gcc/testsuite/gcc.target/i386/pr37843-2.c new file mode 100644 index 0000000..6b26d0d --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr37843-2.c @@ -0,0 +1,12 @@ +/* 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(); +} diff --git a/gcc/testsuite/gcc.target/i386/pr37843-3.c b/gcc/testsuite/gcc.target/i386/pr37843-3.c new file mode 100644 index 0000000..7923b29 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr37843-3.c @@ -0,0 +1,13 @@ +/* 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); +} |