<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/60689>60689</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
C++11 attribute [[gnu::flatten]] doesn't inline all functions recursively (but g++ does)
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
swesterfeld
</td>
</tr>
</table>
<pre>
Here is a code snippet. When compiled with g++ -O3, the `x()` and `y()` functions are inlined into the `z()` function. When compiled with clang++-15, the `z()` function is not flattened. Under gcc the attribute applies recursive to all functions called by `z()`. Since the attribute is called `[[gnu::flatten]]` I'd expect clang++ to do the same thing that gcc does.
```
extern float foo (float f);
// generate lots of code
template<int T>
inline float
x (float f)
{
if constexpr (T > 0)
{
return foo (x<T - 1> (f));
}
else
{
return 0;
}
}
inline float
y (float f)
{
f += x<100> (f);
return f;
}
[[gnu::flatten]]
float z ()
{
y (0);
}
```
Here is a godbolt link: https://godbolt.org/z/zdn7z1zfn
The gerenated code for `z()` looks like this for clang++-15
```
z(): # @z()
push rax
xorps xmm0, xmm0
call float x<99>(float)
call foo(float)@PLT
[...]
```
As you can see, the `z()` function here calls the `x<99>` function, where I'd expect it to inline it.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEVVFvpDYQ_jXel1GQsQOEBx42ya1aqVIrNVWfDR7AjddG2Fw2-fWVDcuye7lLRGBtfzPfN57xWDinOoNYkeyRZM87MfnejpV7Q-dxbFHLXW3le_UbjgjKgYDGSgRn1DCgT-DfHg009jgojRLelO-hI-yRsEe4-5MT9gS-RyA5PRH2QFhJcgrCyDDzfplpJ9N4ZY0DEWiMVgYlKOPt2fzjR_Cn5I0WZhFwl2Yb_k8chHiM9dBq4T0alAn8YySO0DVNNBPej6qePIIYBq3QwYjNNDr1HcFbEFpvlDdCBxX1-zVbAn8r0-CNP7XiSU7j1j92ZiJ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