<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Small testcase uses extreme amount of memory if compiled with -g"
   href="http://llvm.org/bugs/show_bug.cgi?id=19031">19031</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Small testcase uses extreme amount of memory if compiled with -g
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>dimitry@andric.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=12180" name="attach_12180" title="Small testcase using way too much memory for its size">attachment 12180</a> <a href="attachment.cgi?id=12180&action=edit" title="Small testcase using way too much memory for its size">[details]</a></span>
Small testcase using way too much memory for its size

A post on the FreeBSD toolchain mailing list showed a clang crash due to OOM:
<a href="http://lists.freebsd.org/pipermail/freebsd-toolchain/2014-February/001125.html">http://lists.freebsd.org/pipermail/freebsd-toolchain/2014-February/001125.html</a>

the log of the build is here (crash is at the end):
<a href="http://beefy2.isc.freebsd.org/bulk/head-amd64-default/2014-02-28_01h43m56s/logs/arx-libertatis-1.0.3_2.log">http://beefy2.isc.freebsd.org/bulk/head-amd64-default/2014-02-28_01h43m56s/logs/arx-libertatis-1.0.3_2.log</a>

The OP notes an RSS of 15GB.  I did some creduce'ing on his sample files, using
clang trunk r202496, and ended up with the attached sample program, just ~100
lines of code.  If you compile this with just -O2, it is very fast to compile,
and uses little memory:

$ time -l clang -cc1 -triple x86_64-unknown-freebsd11.0 -emit-obj
-mrelocation-model static -O2 too-much-mem.cpp
too-much-mem.cpp:40:1: warning: inline namespaces are a C++11 feature
inline namespace __1 {
^
1 warning generated.
        0.04 real         0.02 user         0.00 sys
     19020  maximum resident set size
     42992  average shared memory size
       101  average unshared data size
       298  average unshared stack size
      1057  page reclaims
         0  page faults
         0  swaps
         0  block input operations
         1  block output operations
        20  messages sent
         0  messages received
         0  signals received
        22  voluntary context switches
         0  involuntary context switches

if you add -g, though, it suddenly balloons to ~2.5 GiB!  E.g.:

$ time -l clang -cc1 -triple x86_64-unknown-freebsd11.0 -emit-obj
-mrelocation-model static -O2 -g too-much-mem.cpp
too-much-mem.cpp:40:1: warning: inline namespaces are a C++11 feature
inline namespace __1 {
^
1 warning generated.
        7.87 real         4.26 user         3.53 sys
   2661660  maximum resident set size
     32178  average shared memory size
        75  average unshared data size
       255  average unshared stack size
   1069959  page reclaims
         0  page faults
         0  swaps
         0  block input operations
         1  block output operations
        27  messages sent
         0  messages received
         0  signals received
        30  voluntary context switches
       167  involuntary context switches

I know generating debug information always uses more memory, but this is a
little bit ridiculous. :-)

Also interesting is that removing the -mrelocation-model static helps:

$ /usr/bin/time -l clang -cc1 -triple x86_64-unknown-freebsd11.0 -emit-obj -O2
-g too-much-mem.cpp
too-much-mem.cpp:40:1: warning: inline namespaces are a C++11 feature
inline namespace __1 {
^
1 warning generated.
        0.07 real         0.01 user         0.03 sys
     19476  maximum resident set size
     19346  average shared memory size
        45  average unshared data size
       153  average unshared stack size
      1156  page reclaims
         0  page faults
         0  swaps
         0  block input operations
         1  block output operations
        36  messages sent
         0  messages received
         0  signals received
        38  voluntary context switches
         0  involuntary context switches

So this seems to be some sort of bad interaction between the static relocation
model and debug information generation?

When building the original testcase from the mailing list, this is all even
worse, and it blows up my testing VM before it can compile, having used up at
least 8GB resident set size.  Similarly to the minimized testcase, removing
-mrelocation-model static allows it to compile, within about 3.5 seconds, and
just 91 MiB of RSS.

I can also reproduce these results on Linux, btw, so it is not specifically
FreeBSD-related.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>