Bug 37843 - [4.4 Regression] unaligned stack in main due to tail call optimization
Summary: [4.4 Regression] unaligned stack in main due to tail call optimization
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.4.0
: P1 normal
Target Milestone: 4.4.0
Assignee: H.J. Lu
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: patch, wrong-code
Depends on:
Blocks:
 
Reported: 2008-10-16 00:48 UTC by H.J. Lu
Modified: 2009-01-15 16:28 UTC (History)
6 users (show)

See Also:
Host:
Target: i?86-*-*
Build:
Known to work: 4.3.2
Known to fail: 4.4.0
Last reconfirmed: 2008-11-01 11:36:26


Attachments
assembly file for gcc.target/i386/pr37843-1.c on i686-apple-darwin9 (244 bytes, text/plain)
2008-11-26 04:26 UTC, Jack Howarth
Details
assembly file for gcc.target/i386/pr37843-2.c on i686-apple-darwin9 (244 bytes, text/plain)
2008-11-26 04:28 UTC, Jack Howarth
Details
An updated patch (1.37 KB, patch)
2008-12-09 22:34 UTC, H.J. Lu
Details | Diff
Here is the updated patch. (1.38 KB, patch)
2009-01-15 15:18 UTC, H.J. Lu
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2008-10-16 00:48:11 UTC
[hjl@gnu-6 880]$ cat x.c
extern int foo ();

int main()
{
    return foo();
}
[hjl@gnu-6 880]$ rm x.s
[hjl@gnu-6 880]$ cat x.c
extern int foo ();

int main()
{
    return foo();
}
[hjl@gnu-6 880]$ make
/export/gnu/import/svn/gcc-test/bld/gcc/xgcc -B/export/gnu/import/svn/gcc-test/bld/gcc/ -O2 -m32 -S -o x.s x.c
[hjl@gnu-6 880]$ cat x.s
        .file   "x.c"
        .text
        .p2align 4,,15
.globl main
        .type   main, @function
main:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $8, %esp
        leave
        jmp     foo

The stack isn't aligned to 16byte.
        .size   main, .-main
Comment 1 H.J. Lu 2008-10-16 01:06:50 UTC
A patch is posted at

http://gcc.gnu.org/ml/gcc-patches/2008-10/msg00670.html
Comment 2 H.J. Lu 2008-10-16 22:14:46 UTC
An updated patch is at

http://gcc.gnu.org/ml/gcc-patches/2008-10/msg00724.html
Comment 3 H.J. Lu 2008-11-01 00:25:58 UTC
I changed it to middle-end.
Comment 4 Richard Biener 2008-11-01 11:36:26 UTC
Confirmed.
Comment 5 H.J. Lu 2008-11-05 14:32:05 UTC
The updated patch is at

http://gcc.gnu.org/ml/gcc-patches/2008-11/msg00130.html
Comment 6 H.J. Lu 2008-11-11 06:49:17 UTC
The current patch is at

http://gcc.gnu.org/ml/gcc-patches/2008-11/msg00180.html
Comment 7 Steven Bosscher 2008-11-18 21:34:22 UTC
P1 bug with a pending patch... maybe a reviewer could take a look at this (seemingly trivial) patch at http://gcc.gnu.org/ml/gcc-patches/2008-11/msg00180.html
?
Comment 8 hjl@gcc.gnu.org 2008-11-25 15:34:50 UTC
Subject: Bug 37843

Author: hjl
Date: Tue Nov 25 15:33:27 2008
New Revision: 142193

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=142193
Log:
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.

Added:
    trunk/gcc/testsuite/gcc.target/i386/align-main-3.c
    trunk/gcc/testsuite/gcc.target/i386/pr37843-1.c
    trunk/gcc/testsuite/gcc.target/i386/pr37843-2.c
    trunk/gcc/testsuite/gcc.target/i386/pr37843-3.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/i386/i386.c
    trunk/gcc/testsuite/ChangeLog

Comment 9 Jack Howarth 2008-11-26 04:25:21 UTC
On i686-apple-darwin9, we are failing...

FAIL: gcc.target/i386/pr37843-1.c scan-assembler call[\\t ]*foo
FAIL: gcc.target/i386/pr37843-2.c scan-assembler jmp[\\t ]*foo

at revision 142207.
Comment 10 Jack Howarth 2008-11-26 04:26:48 UTC
Created attachment 16773 [details]
assembly file for gcc.target/i386/pr37843-1.c on i686-apple-darwin9

Created with...

/sw/src/fink.build/gcc44-4.3.999-20081125/darwin_objdir/gcc/xgcc -B/sw/src/fink.build/gcc44-4.3.999-20081125/darwin_objdir/gcc/ /sw/src/fink.build/gcc44-4.3.999-20081125/gcc-4.4-20081125/gcc/testsuite/gcc.target/i386/pr37843-1.c   -O2 -mpreferred-stack-boundary=6 -mincoming-stack-boundary=5 -S  -m32 -o pr37843-1.s
Comment 11 Jack Howarth 2008-11-26 04:28:03 UTC
Created attachment 16774 [details]
assembly file for gcc.target/i386/pr37843-2.c on i686-apple-darwin9

Created with...

/sw/src/fink.build/gcc44-4.3.999-20081125/darwin_objdir/gcc/xgcc -B/sw/src/fink.build/gcc44-4.3.999-20081125/darwin_objdir/gcc/ /sw/src/fink.build/gcc44-4.3.999-20081125/gcc-4.4-20081125/gcc/testsuite/gcc.target/i386/pr37843-2.c   -O2 -mpreferred-stack-boundary=6 -mincoming-stack-boundary=6 -S  -m32 -o pr37843-2.s
Comment 12 H.J. Lu 2008-11-26 05:38:35 UTC
I don't think sibcall work on Darwin. Can you skip them on Darwin?
Comment 13 Jack Howarth 2008-11-26 12:23:31 UTC
Why do we have...

/* { dg-do compile { target { *-*-linux* && ilp32 } } } */

in gcc.target/i386/align-main-3.c and gcc.target/i386/pr37843-3.c
but not gcc.target/i386/pr37843-1.c and gcc.target/i386/pr37843-2.c?
Isn't that the origin of the problem on darwin?
Comment 14 hjl@gcc.gnu.org 2008-11-26 14:53:41 UTC
Subject: Bug 37843

Author: hjl
Date: Wed Nov 26 14:52:12 2008
New Revision: 142222

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=142222
Log:
2008-11-26  H.J. Lu  <hongjiu.lu@intel.com>

	PR middle-end/37843
	* gcc.target/i386/pr37843-1.c: Make it Linux only.
	* gcc.target/i386/pr37843-2.c: Likewise.

Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.target/i386/pr37843-1.c
    trunk/gcc/testsuite/gcc.target/i386/pr37843-2.c

Comment 15 hjl@gcc.gnu.org 2008-11-28 16:32:18 UTC
Subject: Bug 37843

Author: hjl
Date: Fri Nov 28 16:30:56 2008
New Revision: 142259

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=142259
Log:
2008-11-28  H.J. Lu  <hongjiu.lu@intel.com>

	PR middle-end/37843
	* gcc.target/i386/pr37843-1.c: Make it nonpic targets only.
	* gcc.target/i386/pr37843-2.c: Likewise.

Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.target/i386/pr37843-1.c
    trunk/gcc/testsuite/gcc.target/i386/pr37843-2.c

Comment 16 hjl@gcc.gnu.org 2008-11-29 16:33:58 UTC
Subject: Bug 37843

Author: hjl
Date: Sat Nov 29 16:32:35 2008
New Revision: 142278

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=142278
Log:
2008-11-29  H.J. Lu  <hongjiu.lu@intel.com>

	PR middle-end/37843
	* gcc.target/i386/pr37843-3.c: Make it nonpic targets only.

Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.target/i386/pr37843-3.c

Comment 17 Jakub Jelinek 2008-11-29 21:04:29 UTC
Fixed.
Comment 18 H.J. Lu 2008-11-29 21:10:40 UTC
It isn't totally fixed:

FAIL: gcc.target/i386/pr37843-3.c scan-assembler-not call[\\\\t ]*foo
FAIL: gcc.target/i386/pr37843-3.c scan-assembler jmp[\\\\t ]*foo

I only checked in x86 backend change since no one has reviewed the
middle-end change:

http://gcc.gnu.org/ml/gcc-patches/2008-11/msg01309.html
Comment 19 rguenther@suse.de 2008-11-30 11:19:40 UTC
Subject: Re:  [4.4 Regression] unaligned stack in main
 due to tail call optimization

On Sat, 29 Nov 2008, hjl dot tools at gmail dot com wrote:

> ------- Comment #18 from hjl dot tools at gmail dot com  2008-11-29 21:10 -------
> It isn't totally fixed:
> 
> FAIL: gcc.target/i386/pr37843-3.c scan-assembler-not call[\\\\t ]*foo
> FAIL: gcc.target/i386/pr37843-3.c scan-assembler jmp[\\\\t ]*foo
> 
> I only checked in x86 backend change

Which is if course not the right thing to do without XFAILing the
new testcases...

Richard.
Comment 20 Mark Mitchell 2008-12-09 19:34:50 UTC
HJ --

As Richard says, you should not have checked in the new testcases without XFAILs and without having fixed the bug.

Furthermore, your patch to the middle-end is without explanation.  What is the problem?  How does your patch fix the problem?

-- Mark
Comment 21 H.J. Lu 2008-12-09 22:34:53 UTC
Created attachment 16868 [details]
An updated patch

This patch adds some comments to middle-end change. It also
replaces _Decimal128 with __m128 in gcc.target/i386/pr37843-3.c
so that it can run for all ia32 targets.
Comment 22 H.J. Lu 2008-12-09 22:36:13 UTC
(In reply to comment #20)
> HJ --
> 
> As Richard says, you should not have checked in the new testcases without
> XFAILs and without having fixed the bug.
> 
> Furthermore, your patch to the middle-end is without explanation.  What is the
> problem?  How does your patch fix the problem?
> 

Hi Mark,

Thanks for looking into this. I uploaded a new patch at

http://gcc.gnu.org/bugzilla/attachment.cgi?id=16868

with comments to middle-end changes.
Comment 23 Jakub Jelinek 2009-01-15 15:08:09 UTC
Please s/incomoing/incoming/g in the patch.  Otherwise the patch makes a lot of sense to me.  As INCOMING_STACK_BOUNDARY is used not only in expand_stack_alignment, but also in 386's targetm.function_ok_for_sibcall (and i386 is the only target that has variable INCOMING_STACK_BOUNDARY ATM).  This target hook is called from expand_call, indirectly from expand_gimple_basic_block.  expand_stack_alignment is called after all the expand_gimple_basic_block calls, and the patch moves INCOMING_STACK_BOUNDARY initialization before those calls.
Comment 24 H.J. Lu 2009-01-15 15:18:45 UTC
Created attachment 17107 [details]
Here is the updated patch.
Comment 25 Diego Novillo 2009-01-15 15:23:28 UTC
(In reply to comment #24)
> Created an attachment (id=17107) [edit]
> Here is the updated patch.

OK.


Diego.

Comment 26 hjl@gcc.gnu.org 2009-01-15 15:44:53 UTC
Subject: Bug 37843

Author: hjl
Date: Thu Jan 15 15:44:41 2009
New Revision: 143400

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=143400
Log:
gcc/

2009-01-15  H.J. Lu  <hongjiu.lu@intel.com>
	    Joey Ye  <joey.ye@intel.com>

	PR middle-end/37843
	* cfgexpand.c (expand_stack_alignment): Don't update stack
	boundary nor check incoming stack boundary here.
	(gimple_expand_cfg): Update stack boundary and check incoming
	stack boundary here.

gcc/testsuite/

2009-01-15  H.J. Lu  <hongjiu.lu@intel.com>

	PR middle-end/37843
	* gcc.target/i386/pr37843-3.c: Replace _Decimal128 with __m128.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/cfgexpand.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.target/i386/pr37843-3.c

Comment 27 Jakub Jelinek 2009-01-15 16:28:37 UTC
Fixed, thanks.