This is the mail archive of the gcc-bugs@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]

c/9624: Stack space allocation for automatic variables seems incorrect in many cases


>Number:         9624
>Category:       c
>Synopsis:       Stack space allocation for automatic variables seems incorrect in many cases
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Sat Feb 08 00:26:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Daniel Thom <dath@ficker.net>
>Release:        Reading specs from /usr/lib/gcc-lib/i486-suse-linux/3.2/specs
>Organization:
>Environment:
SuSE Linux Enterprise Server 8 (SLES8)
Linux alice 2.4.19-4GB #1 Mon Oct 21 18:28:11 UTC 2002 i686 unknown
>Description:
gcc 3.2 allocates more stack space than necessary in many cases.  Given the code listed in the "How-To-Repeat" section, I see the following amounts of space allocated on the stack in function():

buf[1-2]   subl    $4, %esp
buf[3]     subl    $24, %esp
buf[4]     subl    $4, %esp
buf[5-7]   subl    $24, %esp
buf[8]     subl    $8, %esp
buf[9-16]  subl    $24,%esp
buf[17-32] subl    $40, %esp

...  I quit there, but I believe the oddities do continue further.  I used the following command line to produce these results:

gcc -DSIZE=1 -S -o test1.S test.c
gcc -DSIZE=2 -S -o test2.S test.c
gcc -DSIZE=3 -S -o test3.S test.c
...

Below is the complete output from test3.S (sorry don't know if you need or want it, but just to error on the side of too much information...):
        .file   "test.c"
        .text
        .align 2
.globl function
        .type   function,@function
function:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $24, %esp
        leave
        ret
.Lfe1:
        .size   function,.Lfe1-function
        .align 2
.globl main
        .type   main,@function
main:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $8, %esp
        andl    $-16, %esp
        movl    $0, %eax
        subl    %eax, %esp
        call    function
        leave
        ret
.Lfe2:
        .size   main,.Lfe2-main
        .ident  "GCC: (GNU) 3.2"
>How-To-Repeat:
void function() { char buf[SIZE]; }
int main(void){ function(); }
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
 Configured with: ../configure --enable-threads=posix --prefix=/usr --with-local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib --enable-languages=c,c++,f77,objc,java,ada --enable-libgcj --with-gxx-include-dir=/usr/i nclude/g++ --with-slibdir=/lib --with-system-zlib --enable-shared --enable-__cxa_atexit i486-suse-linux
 Thread model: posix
 gcc version 3.2


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