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

    <tr>
        <th>Summary</th>
        <td>
            [Itanium ABI] If we can make __cxa_end_catch calls nounwind conditionally
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            c++,
            ABI
      </td>
    </tr>

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

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

<pre>
    This was discussed in https://reviews.llvm.org/D108905.

The simple background is:

```C++
void bar();
void foo() {
    try {
        bar();
    } catch(...) {}
}
```

>From the perspective of programmers, foo() should be clearly noexcept (although this is not completely correct). And the root cause here is that `__cxa_end_catch ` is not unwind.

In D108905 we want to make __cxa_end_catch calls nounwind unconditionally. But it gets blocked since the behavior is wrong in certain cases if the destroying exception can throw an exception: https://godbolt.org/z/PYnj85Pdq. Like the case shows, `foo()` in the above case is not 100% noexcept. So the current behavior is correct.

However, we know it is really rare that the destroying exception can throw and exception and this problem is relatively important in C++ coroutines. Since C++ coroutines are nearly wrapped in big try catch generated by compiler:

```C++
try {
   coroutine function body
} catch (...) {
   promise.unhandled_exception()
}
final_suspend: // final suspend is guaranteed to not throw
```

So if we can make __cxa_end_catch as nounwind, we can make many coroutines as noexcept automatically.

Given the above two reasons (the exceptional case is rare and it is helpful for a lot of functions), I think it makes sense to make __cxa_end_catch calls nounwind conditionally at least.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyNVU2P4jgQ_TXJpbRRMCTAgUN3o55B2sNIO4fdE3KcIvHg2IztkGF__ZadQEPPqtUofJUrr6pevapUpr5svrfSwcAd1NKJ3jmsQWpovT-5ZP6UsFe6LJ4lDi5T6txlxjZk2s7y1TovsiTfJvnT-Pm9RXCyOymEiotjY02vCS3i3LklZT5eLwl7Dle0no2s6TabsFXC1sn83nwwZjRDspzsQC9vL4-G8Pod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