consider following testcase:

void f( char );
void g( char c )
{
        {
                char buf[ 128 * 1024 ];
                __builtin_memset( buf, 0, sizeof( buf ) );
                c = buf[ 0 ];
        }
        f( c );
}

3.7.2/1:
"(...) the storage for these objects lasts until the block
 in which they are created exits."

in fact gcc-4.2 keeps allocated storage until the end of function.
such situation may lead to stack overflow during few recursive f->g calls.

$ g++ local_buf.cpp -O2 -Wall -S

g(char):
        subq    $131080, %rsp
        movl    $131072, %edx
        xorl    %esi, %esi
        movq    %rsp, %rdi
        call    memset
        movsbl  (%rsp),%edi
        call    f(char)
        addq    $131080, %rsp
        ret


-- 
           Summary: violation of automatic storage duration [basic.stc.auto
                    3.7.2/1].
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pluto at agmk dot net


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

Reply via email to