<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/86849>86849</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Attributes on a function template definition (but not declaration) ignored if instantiation occurs before definition
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
dwblaikie
</td>
</tr>
</table>
<pre>
Given:
```
void f();
template <bool>
#ifdef ATTR_DECL
__attribute__((noinline))
#endif
void f1();
int main() {
f1<false>();
}
template <bool>
__attribute__((noinline)) void f1() { f(); }
```
https://godbolt.org/z/MG4qsxvj1
`f1` does not have the `noinline` attribute in the IR/from Clang's CodeGen - but if `ATTR_DECL` is defined or `main` is moved to after `f1`'s definition, the attribute is emitted.
GCC does have the same behavior, so one could argue this is intentional/consistent/correct - but seems a bit off? Curious to get some opinions at least
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEU02P4zYM_TXyhZjAlj9iH3yY9awHBdrLYu-BbNEOt7I4leRs219fSEkz2bkMEMQQKT6-90gp72m1iL2ov4j6JVN7OLPr9c_JKPqTMJtY_9O_0gWtKJ9F_iLyZ9Hkt186Xpg0LEK2Qnai_HINBtzejAoIohwmZiPKr7diWdKicYHn79-_nV6-Dr9f46eTCsHRtAc8nRJYa5msIYsRV3b3crSalsfWxYfeZANsiuw1DOJ4iwNAvFwOizIeI6Nf68Tx5RPyn5KEXxjF1g_OwL3BBwfPIbz5aK8chRxX1hObcGC3Cjn-K-T4x2v1l__78qO4Vy-FaHLQjB4sBzirC0I4I4gmvxNqcrizBbIp_9s3IcfF8QaDUXYV8uhhYI2vaOEJpj0ALRHkfThNDuRB40IWNbCL2WTuNbHxBTUEBrUETMlELQGnIgrEVsghtX_g4wE3CgH14SYq_b8Ow1XVXZFXG8KEZ3UhdhHHM7BFmHk3GpRb93iPfEQkG9DGfsoIOc5sPfkYSQfncA43kR5x86BgogC8LKIcYdgd8e6jlBUDeN4Q-I0ssfWgAhhUPjxSzXRf6q7sVIZ9cSyKuqnqY52d-6JpW9m1zTQtOaom17qZu7orUXdTVWGdUS9zWeWlPBZt2RT1AfOyrZSUhVTVUZe1qHLcFJmDMZct7kFG3u_Yt01bdZlRExqfHqyUFn9CSgop4_t1fax5mvbViyo35IN_RwkUDPbP_w_BA1tQsOx2jqbBfe3fBwdCttGwuGQaZ6Ocus6zA1otO9RxYcj6oGyglAOe5915mHBh94iV7c70H1adwnmfDjNvQo6R5u3z9Ob4B85xcEmcF3JM4v8LAAD__yOxc1A">