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]

[Bug c/45528] New: Variable length array cause repeated alloca() in a loop


When a variable length array is defined in a loop, a call of alloca() is
placed in the loop, and causes stack overflow.

I believe this shouldn't happen since "The space for a variable-length
array is deallocated as soon as the array name's scope ends." (quote
from the doc)
http://gcc.gnu.org/onlinedocs/gcc-4.3.5/gcc/Variable-Length.html

$ cat test.c
int const n = 10000;
void g(int* p);
void f(void)
{
    int i;
    for (i = 0; i < 10000; ++i)
    {
        int a[n];
        g(a);
    }
}

$ gcc --version
gcc (GCC) 4.3.4 20090804 (release) 1
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ uname -a
CYGWIN_NT-5.1 prime 1.7.5(0.225/5/3) 2010-04-12 19:07 i686 Cygwin

$ gcc -S -Os -o - test.c
(snip)
L2:
        movl    %esp, %ebx
        call    __alloca
        leal    19(%esp), %eax
        addl    $1, %esi
        andl    $-16, %eax
        movl    %eax, (%esp)
        call    _g
        cmpl    $10000, %esi
        movl    %ebx, %esp
        jne     L2
(snip)


-- 
           Summary: Variable length array cause repeated alloca() in a loop
           Product: gcc
           Version: 4.3.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: k_satoda at f2 dot dion dot ne dot jp


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45528


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