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

    <tr>
        <th>Summary</th>
        <td>
            Severe memory usage regression since "[clang] Instantiate concepts with sugared template arguments"
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang,
            c++,
            regression
      </td>
    </tr>

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

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

<pre>
    CC @mizvekov @erichkeane @AaronBallman

Since commit b8064374b217db061213c561ec8f3376681ff9c8, "[clang] Instantiate concepts with sugared template arguments", Clang uses a lot more memory (and runs much slower) when compiling some C++ sources.

Previously, the libcxx testsuite ran successfully on Windows on GitHub Actions runners (2 cores, 7 GB of RAM), now after this, at least a handful of testcases fail, running out of memory when compiling them. The libcxx pre-merge CI (which is absolutely central to libcxx development) currently runs with existing stable releases of Clang on Windows - it's not known if they would run successfully with the very latest Clang on the runners used there.

Attached is the preprocessed source of one testcase that runs out of memory: [ranges_merge_preproc.zip](https://github.com/llvm/llvm-project/files/10127365/ranges_merge_preproc.zip)

On Linux, when compiled with Clang 59f0827e2cf3755834620e7e0b6d946832440f80 (the commit preceding b8064374b217db061213c561ec8f3376681ff9c8):
```
$ /usr/bin/time -v clang -target x86_64-windows-gnu -w -c ranges_merge_preproc.cpp -std=c++2b
[...]
        User time (seconds): 10.21
        System time (seconds): 0.31
[...]
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:10.53
[...]
        Maximum resident set size (kbytes): 295716
[...]
```

When compiled with Clang b8064374b217db061213c561ec8f3376681ff9c8:
```
$ /usr/bin/time -v clang -target x86_64-windows-gnu -w -c ranges_merge_preproc.cpp -std=c++2b
[...]
        User time (seconds): 37.39
        System time (seconds): 2.04
[...]
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:39.46
[...]
        Maximum resident set size (kbytes): 1605712
[...]
```
The memory usage rises from ~288 MB to ~1568 MB, and runtime goes from 10 seconds to 39 seconds.

On Windows, when timed with https://github.com/sgraham/tim. Before:
```
> tim clang++.exe -w -c ranges_merge_preproc.cpp -std=c++2b

peak memory: 210.67MB
real: 0m5.796s
qpc: 5807460us
```
After:
```
> tim clang++.exe -w -c ranges_merge_preproc.cpp -std=c++2b

peak memory: 1570.73MB
real: 0m19.125s
qpc: 19137796us
```

So the memory usage rises from ~210 MB to ~1570 MB, and runtime goes from 6 seconds to 19 seconds.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzVV9tu4zYQ_Rr7hbDAi64PfrBz2S7QRYvuFvu4oCja5oYSXZKynf36zkjyxkmTYFO0KBoYknibmXPmDMnUrrlfXl2RWUpb8-2g79wBv7U3anenZaextZLedWtpbSu7Gb2e0dX4_Gg6pYlybWsiqUuap6JIa86KpqY540yoLGdalRshijwv2WZTqXLGwRvns2ytrOy2s-yavO9ClF00MqI1sLmPgRxN3JHQb6XXDYm63Vscln7bt7qLAU2ApSu0QfqgA5HEukha5zVpNbzuwU0pu4b4vguk7RWYs-6o_YxX5LjTHUa-N9aAgeBaTa5mfA0_aPRe6ZBcQv3V64NxfbD36DXuNLGmVqcTRBZi6A2E5mUH8SpYGTa9tffEdeSz6Rp3DPj5zsSf-pqsVDQO4oGgOu0DxsghEK8DGi7IuzVxG_Lb6gNEiT2dOxK5idqDUzPMkZFYLUMEwDuAB75wBcahJPKwkcbiPPSA2FwfccLEyRPggKRNyKcHPHuvF632W6DjPQZ33IESiAF66-BsHzUAU5AALy2J7ryq0Qdt3R4zg-yq3nv4hKkD90Mq9cmEOHAdZW2BLo0oIF6IbcziBV8LYsBQEQB-JHfAQUfMBoMFAK63Q04fkz34wLwcNKBErQBD3-3iwJlxEEuDHV4_yvAqRql2MARYcToQsfcOHUDfKAkM1UFJnLmGeZCMAeIjkmdiRUDfIIitDl8GNr9M5pJvZg-SB2J3Me4DzJzxW_htIfy-TiAx0LD2cH4t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