<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/77482>77482</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang C++20 coroutine miscompilation
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
kelbon
</td>
</tr>
</table>
<pre>
I have generator coroutine, I just added [[gnu::pure]] for my constructor
```cpp
struct A {
B* ptr;
[[gnu::pure]] A(B& b) : ptr(std::addressof(b)) {}
};
```
This provokes segfault on this code:
```cpp
dd::generator<int> foo() {
co_yield 0;
}
int main() {
for (int i : foo())
;
}
```
I had minimized code and in minimized example there is link between [[always_inline]] on await suspend and this segfault (yes i know how clang coroutines work, but i feel that problem not here or not only here)
So, here minimized code:
https://godbolt.org/z/Eadnefe1v
I tried to understand what happens and where exactly bug, but its strange
Locally reproduces even without [[always_inline]] (clang 17 (not clang-cl) windows 11)
May be inline in final awaiter await suspend (its interesting when final_awaiter is promise itself), may be in combination, may be its really just [[pure]] attribute forces compiler to 'forget' to call constructor and initialize memory
Full code:
https://godbolt.org/z/rd167d79q
(segfault locally)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVc9uqzoTfxpnM2oFJglkwSJpTqQjfd_q3n1l8AR8amyuPYRDn_7KdpqmOVKlK0UEhpnx_P7YCO9VZxBrtjmwzXElJuqtq99QN9asGiuX-if04oLQoUEnyDporbMTKYOMv8BP-DV5AiElSohNDp2ZWLFnxX6cHLLNkW2OcLYOhgVaazy5qSXrWHZk2f563Wbp145jiqQs2AMrDykCcGB8DyM5Vhzui-GbZfeMVwfGt9AwvgNWpHpeeZIpV0jp0Ht7ZrwKOTGtPLDy-GW-8viw6G3i9Ph3rzyMzl7sG3rw2J3FpAmsAQpvWisxrPctZHkd6UY0K16UIVb8gLO1jFcfsyXUrX1dFGoJ2edoH1MrQzAIZf4oAoh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