<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/71572>71572</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[OpenMP] No warnings emitted when an exception is thrown in a lambda inside a target region
</td>
</tr>
<tr>
<th>Labels</th>
<td>
openmp
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
AntonRydahl
</td>
</tr>
</table>
<pre>
I have found a bug that most likely has been introduced by myself. In the early summer we changed the way exceptions are handled in OpenMP offloading. Before, we would error out if the target code contained exception handling, and now we emit the code for the try statement and emit a trap instruction for the throw expression. In addition, we print warnings.
For exception handling directly embedded in target regions, and for functions declared target, we get warnings as expected. For instance, compiling the following example
```C++
void foo(double * a){
try {
throw 3;
}
catch (int e) {
*a = e;
}
}
#pragma omp declare target indirect to(foo)
int main(int, char**) {
#pragma omp target
{
double ab = 1;
foo(&ab);
}
return 0;
}
```
gives the warnings
```
warning: target 'amdgcn-amd-amdhsa' does not support exception handling; 'throw' is assumed to be never reached [-Wopenmp-target-exception]
3 | throw 3;
| ^
warning: target 'amdgcn-amd-amdhsa' does not support exception handling; 'catch' block is ignored [-Wopenmp-target-exception]
2 | try {
```
However, the following example does not produce a warning:
```C++
int main(int, char**) {
// lambda that throws an exception
auto lam = [](double& n){
try {
throw 3;
}
catch (int e) {
n = e;
}
};
#pragma omp target
{
double ab = 1;
lam(ab);
}
return 0;
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0Vk1v4zYQ_TX0ZWBDpizLOvjgJDW6h36gl55H5FhilyIFkorjf1-Qkqx4kV00KBZQYsucjzdv3pBE71VjiI6seGLFywqH0Fp3PJlgzV83ia1e1Vbejl-gxVeCix2MBIR6aCC0GKCzPoBWX0nfoEUPNZEBZYKzchAkob5Bd_OkLxv4YiC0BIRO38APXUcOrgSiRdOQTGtXvAG9CeqDssYDOoIWjdQkQRn4oyfz259gLxd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