Bug 36584 - [4.3/4.4 Regression] Stack is not aligned correctly in recursive function
Summary: [4.3/4.4 Regression] Stack is not aligned correctly in recursive function
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.4.0
: P1 normal
Target Milestone: 4.3.2
Assignee: Uroš Bizjak
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords:
: 35271 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-06-20 16:39 UTC by Uroš Bizjak
Modified: 2008-06-24 08:02 UTC (History)
3 users (show)

See Also:
Host:
Target: i686-pc-linux-gnu
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-06-21 13:25:05


Attachments
test case (1.04 KB, text/plain)
2008-06-20 16:40 UTC, Uroš Bizjak
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Uroš Bizjak 2008-06-20 16:39:15 UTC
The example that will be attached in the next comment exhibits a problem with recursive functions. It looks that gcc doesn't align stack correctly if the only remaining call (after inlining?) in the function is the call to itself.

Compiling the test source with -O3 -m32 produces:

sbisect:

-4
-8	pushl	%ebp
	movl	%esp, %ebp
-12	pushl	%edi
-16	pushl	%esi
-20	pushl	%ebx
-196	subl	$176, %esp
	movl	32(%ebp), %eax
	...
	movl	%eax, 4(%esp)
0xC4!!	call	sbisect
	movl	40(%ebp), %ecx
	...

^^^^ offset from %esp at call site.

This violates assumption that %esp is aligned to 16 bytes at call sites. When program recurses into the function, the frame gets unaligned, leading to segfaults when aligned insns are used to access the frame.
Comment 1 Uroš Bizjak 2008-06-20 16:40:10 UTC
Created attachment 15796 [details]
test case

The testcase, distilled from povray-3.6.1
Comment 2 Uroš Bizjak 2008-06-21 13:25:05 UTC
Patch at http://gcc.gnu.org/ml/gcc-patches/2008-06/msg01361.html
Comment 3 H.J. Lu 2008-06-21 16:00:18 UTC
*** Bug 35271 has been marked as a duplicate of this bug. ***
Comment 4 Uroš Bizjak 2008-06-23 17:36:30 UTC
Author: uros
Date: Mon Jun 23 17:31:12 2008
New Revision: 137045

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=137045
Log:
	PR middle-end/PR36584
	* calls.c (expand_call): Increase alignment for recursive functions.

testsuite/ChangeLog:

	PR middle-end/PR36584
	* testsuite/gcc.dg/pr36584.c: New test.
	* testsuite/gcc.target/i386/local2.c: Remove invalid test.


Added:
    trunk/gcc/testsuite/gcc.dg/pr36584.c
Removed:
    trunk/gcc/testsuite/gcc.target/i386/local2.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/calls.c
    trunk/gcc/testsuite/ChangeLog
Comment 5 uros 2008-06-24 07:59:03 UTC
Subject: Bug 36584

Author: uros
Date: Tue Jun 24 07:58:17 2008
New Revision: 137059

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=137059
Log:
        PR middle-end/36584
        * calls.c (expand_call): Increase alignment for recursive functions.

testsuite/ChangeLog:

        PR middle-end/36584
        * testsuite/gcc.dg/pr36584.c: New test.
        * testsuite/gcc.target/i386/local2.c: Remove invalid test.


Added:
    branches/gcc-4_3-branch/gcc/testsuite/gcc.dg/pr36584.c
      - copied, changed from r137045, trunk/gcc/testsuite/gcc.dg/pr36584.c
Removed:
    branches/gcc-4_3-branch/gcc/testsuite/gcc.target/i386/local2.c
Modified:
    branches/gcc-4_3-branch/gcc/ChangeLog
    branches/gcc-4_3-branch/gcc/calls.c
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog

Comment 6 Uroš Bizjak 2008-06-24 08:02:03 UTC
Fixed for mainline and 4.3 branch.
Comment 7 hjl@gcc.gnu.org 2008-06-27 13:59:53 UTC
Subject: Bug 36584

Author: hjl
Date: Fri Jun 27 13:59:05 2008
New Revision: 137179

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

	PR middle-end/36584
	* gcc.target/i386/stackalign/local-1.c: Remove invalid test.

Removed:
    branches/stack/gcc/testsuite/gcc.target/i386/stackalign/local-1.c
Modified:
    branches/stack/gcc/testsuite/ChangeLog.stackalign