public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/55442] New: G++ uses up all my RAM when compiling a constexpr with exponential call graph
@ 2012-11-22 16:28 david at aitellu dot com
  2012-11-22 17:01 ` [Bug c++/55442] " hubicka at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: david at aitellu dot com @ 2012-11-22 16:28 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 55442
           Summary: G++ uses up all my RAM when compiling a constexpr with
                    exponential call graph
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: david@aitellu.com


I have compiled the following program on GCC 4.7.2 and the latest 4.8, using
Ubuntu 12.10 with Linux kernel 3.5.0:

const int MAXD = 24;

constexpr int count(int n, int depth=1){
  return depth == MAXD ? n + 1: count(count(n, depth + 1), depth + 1) + 1;
}

#include<iostream>

int main(){
  constexpr int i = count(0);
  std::cout << i << std::endl;
}

Both versions of GCC will use over 3.3 gig RAM in about 30 seconds. For each
step I increase MAXD, the RAM usage will double until my computer swaps or the
kernel kills the process.

It will never reach a recursion depth of more than 24, but the call graph is
sort of a binary tree, so it will visit 2^MAXD - 1 nodes. Since the recursion
is so shallow, it should not have to use any memory. Clang 3.1 compiles it
without using "any" memory.

Before posting this report, I asked on Stackoverflow, where it was suggested I
report it here.

My guess is that this has something to do with unlimited memoization?


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-11-22 17:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-22 16:28 [Bug c++/55442] New: G++ uses up all my RAM when compiling a constexpr with exponential call graph david at aitellu dot com
2012-11-22 17:01 ` [Bug c++/55442] " hubicka at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).