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

           Summary: memory exhausted compiling a destructor with an
                    infinite 'for (;;);' loop
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: g...@abeckmann.de


The following piece of code consumes all available memory when being compiled
with g++ 4.5 or g++ 4.6 and optimization level -O2 or higher. It compiles
correctly with g++ 4.4.

gcc version 4.6.0 20110111 (experimental) (GCC)
gcc version 4.5.3 20110110 (prerelease) (GCC)

===== 8< =====
struct V
{
        V ( int = 0 ) ;
        ~V ()
        {
                for ( ; ; ) ;
        }
        int size () ;
} ;
struct S
{
        V a ;
        V b ;
        S () : b ( a . size () )
        { }
} ;
S s ;
===== >8 =====

$ ulimit -v
7000000
# limited to about 7 GB ouf of my 8 GB of RAM so the machine does not start to
swap heavily

$ g++-trunk -O2 -c memhog.C
virtual memory exhausted: Cannot allocate memory

$ g++-trunk -v -O2 -c memhog.C
Using built-in specs.
COLLECT_GCC=/opt/software/x86_64/gcc-trunk/bin/g++-trunk
COLLECT_LTO_WRAPPER=/opt/software/x86_64/gcc-trunk/libexec/gcc/x86_64-unknown-linux-gnu/4.6.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-trunk/configure --prefix=/opt/software/x86_64/gcc-trunk
--program-suffix=-trunk --enable-languages=c,c++ --enable-checking
Thread model: posix
gcc version 4.6.0 20110111 (experimental) (GCC)
COLLECT_GCC_OPTIONS='-v' '-O2' '-c' '-shared-libgcc' '-mtune=generic'
'-march=x86-64'

/opt/software/x86_64/gcc-trunk/libexec/gcc/x86_64-unknown-linux-gnu/4.6.0/cc1plus
-quiet -v -D_GNU_SOURCE memhog.C -quiet -dumpbase memhog.C -mtune=generic
-march=x86-64 -auxbase memhog -O2 -version -o /tmp/ccmZpTnX.s
GNU C++ (GCC) version 4.6.0 20110111 (experimental) (x86_64-unknown-linux-gnu)
        compiled by GNU C version 4.6.0 20110111 (experimental), GMP version
4.3.2, MPFR version 3.0.0-p3, MPC version 0.8.2
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
ignoring nonexistent directory
"/opt/software/x86_64/gcc-trunk/lib/gcc/x86_64-unknown-linux-gnu/4.6.0/../../../../x86_64-unknown-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:

/opt/software/x86_64/gcc-trunk/lib/gcc/x86_64-unknown-linux-gnu/4.6.0/../../../../include/c++/4.6.0

/opt/software/x86_64/gcc-trunk/lib/gcc/x86_64-unknown-linux-gnu/4.6.0/../../../../include/c++/4.6.0/x86_64-unknown-linux-gnu

/opt/software/x86_64/gcc-trunk/lib/gcc/x86_64-unknown-linux-gnu/4.6.0/../../../../include/c++/4.6.0/backward
 /opt/software/x86_64/gcc-trunk/lib/gcc/x86_64-unknown-linux-gnu/4.6.0/include
 /usr/local/include
 /opt/software/x86_64/gcc-trunk/include

/opt/software/x86_64/gcc-trunk/lib/gcc/x86_64-unknown-linux-gnu/4.6.0/include-fixed
 /usr/include
End of search list.
GNU C++ (GCC) version 4.6.0 20110111 (experimental) (x86_64-unknown-linux-gnu)
        compiled by GNU C version 4.6.0 20110111 (experimental), GMP version
4.3.2, MPFR version 3.0.0-p3, MPC version 0.8.2
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: e48296e048ab4023a18c7e7537bfd602
virtual memory exhausted: Cannot allocate memory

Reply via email to