<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/61040>61040</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Modules] Initializers of used variable templates evaluated in every importer
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
davidstone
</td>
</tr>
</table>
<pre>
Given the following two translation units:
```cpp
export module a;
#define REPEAT8(x) \
(x), \
(x), \
(x), \
(x), \
(x), \
(x), \
(x), \
(x)
unsigned a() {
unsigned x = 0;
REPEAT8(REPEAT8(REPEAT8(REPEAT8(REPEAT8(REPEAT8(++x))))));
return x;
}
template<typename>
unsigned aa = a();
void aaa() {
aa<int>;
}
```
```cpp
export module b;
import a;
```
And compiled with
```shell
clang++ -std=c++20 -x c++-module --precompile -c a.cpp -o a.pcm
clang++ -std=c++20 -fmodule-file=a=a.pcm -x c++-module -c b.cpp
```
Causes the compilation of b.cpp to take longer than expected, especially if optimizations are turned on. Passing -ftime-trace shows that most of the non-optimizer time is spent in EvaluateAsInitializer on `aa`. If optimizations are turned on, it then spends a bunch of extra time compiling `module b` for optimizations, primarily SROAPass, but that is possibly just a duplicate of https://github.com/llvm/llvm-project/issues/60996
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVd2uozYQfhrnZkTkmJ-ECy5ykpNqL6qutn2BwQzBW2Mj2-SnT18ZknNyTqOqq96sRAiMh_l-PLbRe3U0RBXLX1i-X-AYOuuqBk-q8cEaWtS2uVa_qBMZCB1Ba7W2Z2WOEM4WgkPjNQZlDYxGBc_SLeN7xu_3gs-XHIY5QpfBugC9bUZNgCx9-ZAv0oZaZQi-vX593f6xYWJzYaIElu_ueeUtxsTuJw8_Cpvuo5ncbgCZ2Eyy1m_yy7fBC7B0D_zBmvLdjR9_YuKFiZeZ58frAcBRGJ2By3tsvX9kHqgfNAZi6S5cBzL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