<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/124749>124749</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            inordinate memory usage and excessive build times with -O2 and -g
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          rnagy
      </td>
    </tr>
</table>

<pre>
    While compiling Cython I've noticed that clang18 up to git HEAD, is using inordinate amounts of memory
while building with -O2 and -g.

Bisecting shows that the commit that causes the issue is 5d5583979179e3b0702888adf188b10831037758

I've attached a pre-processed file that can be used to reproduce the issue:

`$ /usr/bin/time -v clang -O2 -g -c Code.i -o Code.o`

Current status (virt memory hits 10G+):
```
 Command being timed: "clang -O2 -g -c Code.i -o Code.o"
 User time (seconds): 179.

[Code.i.gz](https://github.com/user-attachments/files/18574396/Code.i.gz)

34
 System time (seconds): 4.36
        Percent of CPU this job got: 99%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 3:03.73
 Average shared text size (kbytes): 0
        Average unshared data size (kbytes): 0
        Average stack size (kbytes): 0
        Average total size (kbytes): 0
        Maximum resident set size (kbytes): 8019468
 Average resident set size (kbytes): 0
        Major (requiring I/O) page faults: 0
        Minor (reclaiming a frame) page faults: 2107773
 Voluntary context switches: 1
        Involuntary context switches: 774
 Swaps: 0
        File system inputs: 0
        File system outputs: 11096
        Socket messages sent: 0
        Socket messages received: 0
 Signals delivered: 0
        Page size (bytes): 4096
        Exit status: 0
```
Maximum resident set size (kbytes): 8019468 (virt memory hits 10G+)

Before the offending commit:
```
        Command being timed: "./build/bin/clang-17 -O2 -g -c Code.i -o Code.o"
        User time (seconds): 36.03
        System time (seconds): 0.44
        Percent of CPU this job got: 99%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:36.48
        Average shared text size (kbytes): 0
        Average unshared data size (kbytes): 0
        Average stack size (kbytes): 0
 Average total size (kbytes): 0
        Maximum resident set size (kbytes): 517372
        Average resident set size (kbytes): 0
        Major (requiring I/O) page faults: 0
        Minor (reclaiming a frame) page faults: 183869
        Voluntary context switches: 1
        Involuntary context switches: 148
        Swaps: 0
        File system inputs: 0
 File system outputs: 11096
        Socket messages sent: 0
        Socket messages received: 0
        Signals delivered: 0
        Page size (bytes): 4096
        Exit status: 0
```

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzMVt-PmzgQ_mucl1GQf0AwD3nIps1dH06tVPXu2cAA7oKds02y6V9_MpA2bbe7rXTXK4oCgvnmG8-MP4_yXrcGcUuyO5K9WKkxdNZtnVHtZVXa-rL9q9M9QmWHo-61aWF_CZ018Irw_IRgbNAV1hA6FaDqlWmZhPEIwUKrA_z-cveC8D1oD6OPaG2sq7VRAUENdjTBg21gwMG6C6G780RWjrqvo_VZhw7WrzkoU8O6TQjdEbq70x6rEL_7zp79zB26KchBhyUWNXr002vt_Rj_IauzTIoiL1heoChpTrmUUtUNk7JkVApGRZ5ncqZZVqhCUFWHNSg4Olwfna3Qe6yhiaEuXAZKhDG-DRYcHp2txwo_sROxm52SDSU8BcIPo3eEH0ptCD8EPSCsT3MCpwWvW1hXsLc1JhrWdn6yET252Y_OoQnggwqjB8LlSbuw5BE6HTww-hvhd4QXC_eGLj-6g70dhpjSEmMWI3tNxA4I589GwHl08M6jm3CR2mNlTe1nKmB5sdSJZHczPGk_kOwF4bIL4ehjPPxA-KHVoRvLpLLDlA506znXA5rgCT_EBMc7k1meimJD-OGTP17MJCKN8by9-IDDNyJKE7GJRsv1Bl0Vc2cb2L95B6HTHt7bElobonVREJ7dmL_s1TEWlnB5Vn0PVW-re8KLj2QdEbthIGLnPVgH89NCLYjYUZHkIjrcndCpFsF3ysVOwYcAXn-YnNyXl4BXFL2hv4JGs8BqFdT3w3xQ1f33mwcbVP-8-R_qQQ_jAA69rqc-xG8sRVJWpBt5u_znQZ9TvbcuWjj8e9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